private void SendMessage() { byte[] buffer = Encoding.ASCII.GetBytes(env.Text); env.Text = ""; serialPort1.Write(buffer, 0, buffer.Length); //serialPort1.WriteLine(env.Text); //env.Text = ""; }
private void buttonTest_Click(object sender, RoutedEventArgs e) { byte[] byteList = new byte[4]; byteList[0] = 0x00; byteList[1] = 0x020; byteList[2] = 0x01; byteList[3] = 0x00; //for (int i = 0; i < 20; i++) //{ // byteList[i] = (byte)(2 * i); //} serialPort1.Write(byteList, 0, byteList.Length); }
void UartEncodeAndSendMessage(int msgFunction, int msgPayloadLength, byte[] msgPayload) { int i; byte[] trame = new byte[6 + msgPayload.Length]; trame[0] = 0xFE; trame[1] = (byte)(msgFunction >> 8); trame[2] = (byte)(msgFunction >> 0); trame[3] = (byte)(msgPayloadLength >> 8); trame[4] = (byte)(msgPayloadLength >> 0); for (i = 0; i < msgPayloadLength; i++) { trame[5 + i] ^= msgPayload[i]; } trame[5 + i] = CalculateChecksum(msgFunction, msgPayloadLength, msgPayload); serialPort1.Write(trame, 0, trame.Length); }
void UartEncodeAndSendMessage(int msgFunction, int msgPayloadLength, byte[] msgPayload) { byte[] trame = new byte[6 + msgPayload.Length]; int pos = 0; int i; trame[pos++] = 0xFE; trame[pos++] = (byte)(msgFunction >> 8); trame[pos++] = (byte)(msgFunction >> 0); trame[pos++] = (byte)(msgPayloadLength >> 8); trame[pos++] = (byte)(msgPayloadLength >> 0); for (i = 0; i < msgPayload.Length; i++) { trame[pos++] = msgPayload[i]; } trame[pos++] = CalculateChecksum(msgFunction, msgPayloadLength, msgPayload); serialPort1.Write(trame, 0, pos); }
private void buttonTest_Click(object sender, RoutedEventArgs e) { byte[] byteList = new byte[20]; for (int i = 0; i < 20; i++) { byteList[i] = (byte)(2 * i); } serialPort1.Write(byteList, 0, byteList.Count()); }
private void SendMessage(string msg) { if (emissionFormat == "Hex") { string[] hex_msg = msg.Split(' '); byte[] abc = new byte[hex_msg.Length]; for (int i = 0; i <= hex_msg.Length - 1; i = i + 1) { abc[i] = Convert.ToByte(hex_msg[i], 16); } serialPort.Write(abc, 0, abc.Length); } else { serialPort.Write(msg); } }
void UartEncodeAndSendMessage(int msgFunction, int msgPayloadLength, byte[] msgPayload) { byte checksum = CalculateChecksum(msgFunction, msgPayloadLength, msgPayload); byte[] msg = new byte[6 + msgPayloadLength]; int pos = 0; msg[pos++] = 0xFE; msg[pos++] = (byte)(msgFunction >> 8); msg[pos++] = (byte)(msgFunction >> 0); msg[pos++] = (byte)(msgPayloadLength >> 8); msg[pos++] = (byte)(msgPayloadLength >> 0); for (int i = 0; i < msgPayloadLength; i++) { msg[pos++] = msgPayload[i]; } msg[pos++] = checksum; serialPort1.Write(msg, 0, 6 + msgPayloadLength); }
/// <summary> /// Get stream chunk size /// </summary> public ushort GetStreamChunkSize() { if (!_connected) { throw new HardwareException("Encryption Module is not connected!"); } if (!IsCommandSupported(Commands.GET_CONFIG_VALUE)) { throw new NotSupportedException("This command is not supported on this device."); } var arr = new byte[2]; var cOffset = 0; // Download listener void Listener(object sender, DataReceivedArgs args) { var len = args.Data.Length; for (var q = 0; q < len; q++) { arr[cOffset] = args.Data[q]; cOffset++; } } _com.DataReceived += Listener; // Send request _com.Write( new byte[] { Commands.GET_CONFIG_VALUE, ConfigIdentifiers.CFG_STREAM_CHUNK_SIZE, Commands.DUMMY }, 0, 3); while (cOffset < 2) { // Do nothing, wait for data } _com.DataReceived -= Listener; // Convert back to ushort return(BitConverter.ToUInt16(new byte[] { arr[^ 1], arr[0] }));
void UartEncodeAndSendMessage(int msgFunction, int msgPayloadLength, byte[] msgPayload) { byte Checksum = 0; byte[] trame = new byte[msgPayloadLength + 6]; int pos = 0; trame[pos++] = (byte)(0xFE); trame[pos++] = (byte)(msgFunction >> 8); trame[pos++] = (byte)(msgFunction >> 0); trame[pos++] = (byte)(msgPayloadLength >> 8); trame[pos++] = (byte)(msgPayloadLength >> 0); for (int i = 0; i < msgPayloadLength; i++) { trame[pos++] = (byte)msgPayload[i]; } Checksum = CalculateChecksum(msgFunction, msgPayloadLength, msgPayload); trame[pos++] = (byte)(Checksum); serialPort1.Write(trame, 0, trame.Length); }
void UartEncodeAndSendMessage(int msgFunction, int msgPayloadLength, byte[] msgPayload) { byte[] sortie = new byte[msgPayloadLength + 6]; sortie[0] = 0xFE; sortie[1] = (byte)((msgFunction & 0xFF00) / 0x100); sortie[2] = (byte)(msgFunction & 0xFF); sortie[3] = (byte)((msgPayloadLength & 0xFF00) / 0x100); sortie[4] = (byte)(msgPayloadLength & 0xFF); for (int i = 0; i < msgPayloadLength; i++) { sortie[i + 5] = msgPayload[i]; } sortie[msgPayloadLength + 5] = CalculateCheckSum(msgFunction, msgPayloadLength, msgPayload); serialPort1.Write(sortie, 0, msgPayloadLength + 6); }
public void UartEncodeAndSendMessage(ushort msgFunction, ushort msgPayloadLength, byte[] msgPayload) { byte[] message = new byte[6 + msgPayloadLength]; int pos = 0; message[pos++] = 0xFE; message[pos++] = (byte)(msgFunction >> 8); message[pos++] = (byte)(msgFunction >> 0); message[pos++] = (byte)(msgPayloadLength >> 8); message[pos++] = (byte)(msgPayloadLength >> 0); for (int i = 0; i < msgPayloadLength; i++) { message[pos++] = msgPayload[i]; } message[pos++] = CalculateChecksum(msgFunction, msgPayloadLength, msgPayload); serialPort1.Write(message, 0, pos); }
// Créer une classe UART ? private void uartEncodeAndSendMsg(ushort msg_func, ushort msg_payload_length, byte[] msg_payload) { int i = 0, j = 0; byte[] msg = new byte[EMPTY_TRAME_SIZE + msg_payload_length]; msg[i++] = 0xFE; msg[i++] = (byte)(msg_func >> 8); msg[i++] = (byte)msg_func; msg[i++] = (byte)(msg_payload_length >> 8); msg[i++] = (byte)msg_payload_length; for (j = 0; j < msg_payload_length; j++) { msg[i++] = msg_payload[j]; } msg[i++] = calcChecksum(msg_func, msg_payload_length, msg_payload); serialPort.Write(msg, 0, msg.Length); }
void UartEncodeAndSendMessage(int msgFunction, int msgPayloadLength, byte[] msgPayload) { // Ici on envoi un message qui comprend SOF, Command, PayloadLength, Payload et CheckSum. byte checksum = CalculateChecksum(msgFunction, msgPayloadLength, msgPayload); byte[] msg = new byte[6 + msgPayloadLength]; int pos = 0; msg[pos++] = 0xFE; msg[pos++] = (byte)(msgFunction >> 8); msg[pos++] = (byte)(msgFunction >> 0); msg[pos++] = (byte)(msgPayloadLength >> 8); msg[pos++] = (byte)(msgPayloadLength >> 0); for (int i = 0; i < msgPayloadLength; i++) { msg[pos++] = msgPayload[i]; } for (int i = 0; i < msg.Length; i++) { textBoxReception.Text += msg[i]; } msg[pos++] = checksum; serialPort1.Write(msg, 0, msg.Length); }
private void SendMessage() { serialPort1.Write(textBoxEmission.Text); textBoxEmission.Text = null; }