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); }
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); }
public void ReadFloatMessage() { var thisMbo = MBLst[1]; var plcRequest = new PlcRequest(true, false); plcRequest.requestBytes = new List <byte>(thisMbo.readCmndMsg); Read32BitMessage(plcRequest); }
public void Read16BitMessage() { var thisMbo = MBLst[2]; var plcRequest = new PlcRequest(false, false); plcRequest.requestBytes = new List <byte>(thisMbo.readCmndMsg); SerialComms.sendMessage(plcRequest); }
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 { } } } }
public void Read32BitMessage(PlcRequest plcRequest) { SerialComms.sendMessage(plcRequest); }