Passing data from C# to ComPort2 (USb to RS232)

Jan 17 2018 4:05 AM
I have a card dispensing device in which I want to be triggered by a C# program.
 
The Card Dispensing Device has a command to trigger the card-out function.
 
 
 
Now when I checked the 42 is a hex and the H is just a hex determinator of some sort.
 
They gave me an exe which do the sending of data but I want to repliacte it and create my own.
 
In the exe that they gave when I press card out it shows a command like this one
 
-->[0x01] [0x42]
 
the first [] is for the device the second [] is the I think ascii hex of the command.
 
Here's the code I have so far
  1. using System.IO.Ports;  
  2. namespace Card_Reader  
  3. {  
  4. public partial class Form1 : Form  
  5. {  
  6. public Form1()  
  7. {  
  8. InitializeComponent();  
  9. }  
  10. private void button1_Click(object sender, EventArgs e)  
  11. {  
  12. using (SerialPort port = new SerialPort("COM2", 9600, Parity.None, 8))  
  13. {  
  14. byte[] bytesToSend = new byte[1] { 0x2A };  
  15. port.Open();  
  16. port.Write(bytesToSend, 0, 1);  
  17. }  
  18. }  
I did not include all closing brackets.

Answers (1)