How can I send a hexadecimal like 0x2b or 0x42 to a serial port using either C# or Php.
42 is the HEX that I need to send by the way.
I used this for C#
using System.IO.Ports;
namespace Card_Reader
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
using (SerialPort port = new SerialPort("COM2", 9600, Parity.None, 8))
{
byte[] bytesToSend = new byte[1] { 0x2A };
port.Open();
port.Write(bytesToSend, 0, 1);
}
}
but nothing happens to the device connected to my serial port.
Now I used this for Php
public function dispense_card() {
$serial = new CI_Phpserial();
// First we must specify the device. This works on both linux and windows (if
// your linux serial device is /dev/ttyS0 for COM1, etc)
$serial->deviceSet("COM2");
// We can change the baud rate, parity, length, stop bits, flow control
$serial->confBaudRate(9600);
$serial->confParity("even");
$serial->confCharacterLength(8);
$serial->confStopBits(1);
$serial->confFlowControl("none");
// Then we need to open it
$serial->deviceOpen();
// To write into
/*$serial->sendMessage(0x42);*/
$str = pack("h*",66);
$serial->sendMessage($str);
}
I'm getting close to hanging myself since I'm trying to do this since last year and until now I cannot accomplish it.
Newbie here when it comes to serial data sending.