Exemplo n.º 1
0
        private void read32_Click(object sender, EventArgs e)
        {
            var thisMbo    = MBLst[3];
            var plcRequest = new PlcRequest(false, true);

            plcRequest.requestBytes = new List <byte>(thisMbo.readCmndMsg);
            Read32BitMessage(plcRequest);
        }
Exemplo n.º 2
0
        private void readInFloat_Click(object sender, EventArgs e)
        {
            var thisMob   = MBLst[4];
            var plcRequst = new PlcRequest(true, true);

            plcRequst.requestBytes = new List <byte>(thisMob.readCmndMsg);
            Read32BitMessage(plcRequst);
        }
Exemplo n.º 3
0
        public void ReadFloatMessage()
        {
            var thisMbo    = MBLst[1];
            var plcRequest = new PlcRequest(true, false);

            plcRequest.requestBytes = new List <byte>(thisMbo.readCmndMsg);
            Read32BitMessage(plcRequest);
        }
Exemplo n.º 4
0
        public void Read16BitMessage()
        {
            var thisMbo    = MBLst[2];
            var plcRequest = new PlcRequest(false, false);

            plcRequest.requestBytes = new List <byte>(thisMbo.readCmndMsg);
            SerialComms.sendMessage(plcRequest);
        }
Exemplo n.º 5
0
        public void sendMessage(PlcRequest plcRequest)
        {
            if (_serialPort != null)
            {
                if (!_serialPort.IsOpen)
                {
                    checkConns();
                }
                List <byte> requestBytes = plcRequest.requestBytes;
                if (requestBytes.Count > 0)
                {
                    byte[] bytesToSend  = new byte[requestBytes.Count + 2]; // the 2 is for the CRC we'll add at the end
                    String sMessageSent = "";
                    UInt16 crc16        = 0xFFFF;
                    for (int i = 0; i < requestBytes.Count; i++)
                    {
                        Byte byteFromArray = (Byte)requestBytes[i];
                        bytesToSend[i] = byteFromArray;
                        crc16          = CalculateCRC(byteFromArray, crc16);
                        sMessageSent  += bytesToSend[i].ToString("X").PadLeft(2, '0') + " ";
                    }

                    bytesToSend[bytesToSend.Count() - 2] = (Byte)(crc16 % 0x100);
                    sMessageSent += bytesToSend[bytesToSend.Count() - 2].ToString("X").PadLeft(2, '0') + " ";

                    bytesToSend[bytesToSend.Count() - 1] = (Byte)(crc16 / 0x100);
                    sMessageSent += bytesToSend[bytesToSend.Count() - 1].ToString("X").PadLeft(2, '0') + " ";

                    form.messageSent.Text = sMessageSent;
                    try
                    {
                        reqType = new ReqType(plcRequest.isFloat, plcRequest.isSigned);
                        _serialPort.Write(bytesToSend, 0, bytesToSend.Length);
                    }
                    catch
                    {
                    }
                }
            }
        }
Exemplo n.º 6
0
 public void Read32BitMessage(PlcRequest plcRequest)
 {
     SerialComms.sendMessage(plcRequest);
 }