0. Connect/Disconnect
//connect
var device = new SecsGem(
        ipAddress ,      /* device address(Active) | local binding address(passive) */
        port ,           /* device tcp port(Active) | local tcp port(passive) */
        isActive ,       /* true(active) | false(passive) */
        socketRecvBufferSize , 
        tracer ,         /* ISecsTracer implementation for logging */
        primaryMsgHandler/* primary message handler deleage */
);

//disconnect
device.Dispose();


1. Send message to device
try{
    var s3f18 = device.Send(s3f17); //direct get device's reply secondary message
    byte returnCode = (byte)s3f18.SecsItem.Items[0]; 
}catch(SecsException){
    // exception occurred if
    // T3 timeout
    // device reply SxF0
    // device reply S9Fx
}

2. Receive message from device
provide a delegate to SecsGem constructor's last argument
(primaryMsg, reply) => {
    try {
       //do something for primaryMsg
       reply( secondaryMsg ); // reply secondary msg to device
    } catch (Exception ex) {
        
    }
};

3. SecsMessage construction is LINQ friendly and it is similar to SML format.
var s16f15 = new SecsMessage(16, 15, "CreateProcessJob",
                Item.L(
                    Item.U4(0),
                    Item.L(from pj in tx.ProcessJobs select
                        Item.L(
                            Item.A(pj.Id),
                            Item.B(0x0D),
                            Item.L(from carrier in pj.Carriers select
                                Item.L(
                                    Item.A(carrier.Id),
                                    Item.L(from slotInfo in carrier.SlotMap select
                                        Item.U1(slotInfo.SlotNo)))),
                            Item.L(
                                Item.U1(1),
                                Item.A(pj.RecipeId),
                                Item.L()),
                            Item.Boolean(true),
                            Item.L()))));
4. SecsMessage is immutable for parallel processing
5. SecsMessage is remoting operatable. It mean you can build an scalable distributed device control system.

Last edited Apr 27, 2013 at 4:18 PM by westjeffho, version 13