Hi,
I'm really new to C++. I'd like to know how to send command to serial ports.
Im connecting to a uniwell POS machine and I dont know what commands I'll be using. They gave me this serial communication protocol manual with this format.
1.4 Clear All Request
It is always safest to clear all existing report requests before you request the days reports. This is done by sending the following request.
SOH C - A STX 0 1 CR LF ETX BCC
how do you send commands like that to a serial port?
Thank you.
9 13162
On windows, open file handle with command like
HANDLE serialhCom = CreateFileA(dev name, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_FLAG_OVERL APPED, NULL);
Then write to it using WriteFile().
On other OS it will differ, it depends on OS more that on language.
hi newb16.
Thanks for the reply.
Yes i've done the connection part and other stuff.. My concern is how to pass that particular command to a serial port. I know it would be using the WriteFile command..
Shall I do it this way?
char strCmd[] = {'S','O','H','F ','-','R','S','T',' X','0','1','C', 'R','L','F','E' ,'T','X','B','C ','C'};
or in hexadecimal format?
char strCmd[] = {0x01,0x46,0x2D ,0x52,0x53,0x54 ,0x58,0x00,0x01 ,0x0D,0x0A,0x03 };
and ive called this function:
BOOL bWriteCmd = objCom->sendData(strCm d,sizeof(strCmd ));
//where sendData() function is declared as member of a class:
DWORD comport::sendDa ta (const char* data, DWORD size)
{
DWORD numberOfBytesWr itten;
WriteFile(_hCom ,
data,
size,
&numberOfBytesW ritten,
0);
return numberOfBytesWr itten;
}
and I've tried to get the machine's reply by calling this function:
DWORD comport::receiv eData (char* data, DWORD size)
{
DWORD numberOfBytesRe ad;
ReadFile(_hCom,
data,
size,
&numberOfBytesR ead,
0);
return numberOfBytesRe ad;
}
coz i've done both strCmd declaration and I haven't received a reply from the pos machine.
Please help. Thank you.
gpraghuram 1,275
Recognized Expert Top Contributor
HI,
U need not convert the command to hexadecimal format and send it.
If you do like that then in the receiving box you have to reconvert it back and execute the command.
So send the command as a string and after reading the command execute it on the other box.
Raghu
Hi Raghu,
Thanks for the reply. I've tried it just now... but still not working. Is there a way that maybe I could get a reply just so I would be sure that I am really transfering a command to the machine? maybe a generic command that would get the machine's address, name.. etc.
gpraghuram 1,275
Recognized Expert Top Contributor
Can you explain in which part u r having issue?
Issue is in the receiving part or in execution of the received command?
raghu
JosAH 11,448
Recognized Expert MVP @Cerebro
In ASCII SOH means 'Start Of Heading' (code 0x01) and STX means 'Start of TeXt' (code 0x02), CR means 'Carriage Return' (code 0x0D), LF means 'Line Feed' (code 0x0A), ETX means "End of TeXt' (code 0x03) but I don't know what the BCC means or how to interpret C - A. Check your manual
kind regards,
Jos
@gpraghuram
hi,
issue is I can't get the machine to respond to my command. It might be that the machine does not understand my command, which is why I was asking how to send the command to serial port, or I'm lost here. I'll read tutorials on the net. Thank you for the response.
@JosAH
Hi Jos,
Yes i know what that means, that's why I was asking how to send those commands to a serial ports..by hex or by string.. coz I still can't get the machine to reply to me.
Thank you for your reply.
JosAH 11,448
Recognized Expert MVP @Cerebro
What I saw from your reply #3 is that you were trying to send the symbolic names of the commands; that's not how you do it; if you have to send:
SOH C - A STX 0 1 CR LF ETX BCC
... you actually have to send the byte values
0x01 'C' '-' 'A' 0x01 '0' '1' 0x0d 0x0a 0x02 'B' 'C' 'C'
I'm not sure about that C - A part and the BCC part, check your manual.
kind regards,
Jos
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: M. Raab |
last post by:
i have written an application that utilizes serail ports. In order not to
have to reinvent code, I decided to use John Hind's sample code that he
presented in MSDN magazine last year (Serial Comm: Use P/Invoke to Develop a
..NET Base Class Library for Serial Device Communications John Hind - MSDN
Magazine - October 2002)
it works fine except for one problem. i cannot address any port higher than
COM9. I am using an equinox multi-serial...
|
by: Al the programmer |
last post by:
I need to access the serial ports on my webserver from an asp.net page. I
have no problem accessing the serial ports from a windows form application,
but the code doesn't work in asp.net. I have been told it is not possible to
access the serial ports from asp.net.
The application is used to control custom hardware. The hardware is
connected to a PC through serial ports. Our customer wants to control the
hardware from a remote...
|
by: David |
last post by:
I have written an application in VB.NET 2003 that uses the SAX serial
component for RS232 communications with hardware.
The program sets up 2 serial ports so that it can talk to 2 different
hardware devices simultaneaously.
When I run the program on a desktop running Windows 2000 it works fine. When
I run it on a Laptop using XP I start having problems.
It seems that when the ports are initiated, either one will work but not the
|
by: Tom Brown |
last post by:
Hey people,
I've written a python app that r/w eight serial ports to control eight devices
using eight threads. This all works very nicely in Linux. I even put a GUI on
it using PyQt4. Still works nicely.
Then I put the app on on a virtual Windows machine running inside of vmware on
the same Linux box. Vmware only lets me have four serial ports so I run the
app against four serial ports using four threads. The app did not respond...
|
by: LongBow |
last post by:
Hello,
Is there a way, in .NET, to determine what are the avialable Serial
(Communications) Ports on a Windows OS and is there a way to determine
that port isn't being use other than attempting to opening the Serial
Port and catching the associated exception? Thanks
If there isn't a way to determine the Serial Port within .NET I would
be willing, I guess, to use a WinAPI is that was the only way.
| |
by: joaquimfpinto |
last post by:
Dear All,
I made an app in c# that uses several serial ports.
For the serial ports I use a pnp Sunix board, some with 8 serial ports
other with 4 or even 2 serial ports.
Whenever I use the development computer I don't have ay problem with
my application.
|
by: pauland80 |
last post by:
Hello,
My soft passively listen to a device sending +- 300 bytes of data each
second. After several hours of work, the soft abruptly stops receiving
data without any error, (while the device sends properly, of course)
and I need to restart it (the python soft) to "reactivate" the ports.
I read that when the serial port encounters an error (frame error or
so, I imagine?) it stop receiving data until the library function...
|
by: naveen.sabapathy |
last post by:
Hi,
I am trying to use virtual serial ports to develop/test my serial
communication program. Running in to trouble...
I am using com0com to create the virtual ports. The virtual ports
seem to be working fine when I test it with Hyperterminal .
I am using the example program that comes with pyserial, as below.
---------------
import serial
|
by: Nasif |
last post by:
Currently I am writing a program which sends and receives messages
through serial port to a device. I am using C# and Microsoft Visual
studio 2005 for windows program. But my problem is when i try to write
in serial port from my windows a Timeoutexception is thrown. I use
SerialPort class in System.IO.Ports and for writing port i used
write() function under the built in class SerialPort. But when i use
hyperterminal , everything goes fine....
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |