- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
While trying to write simple MODBUS Master and Slave applications, I ran into a problem. I tried to send an unsigned char array over RS232 using WriteFile. In the other application, I tried to read the same unsigned char array using ReadFile. I know I have to use pointers, and it works up to a point. I've boiled it down to what looks like a data type range problem, but it shouldn't be.
I began using a single usigned char, defined as:
unsigned char test = 0x01;
and sending the char as &test in the WriteFile. That works fine. When I increase the value to 0x80(128) the value of test on the ReadFile side is 0. Anybody have any clue what's going on here/ how to make this work? I need to be able to have a value of 0xff, and I thought an unsigned char would take care of that.
Happy to post any more code if needed. Thanks.
Chris
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
if VC works, please provide a code snipet around the WriteFile, creating the file andclosing the file.
Jennifer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Opening:
char COM_PORT[] = "COM1";
printf("COM port being used is %s.nn", COM_PORT);
HANDLE hComm;
hComm = CreateFile( COM_PORT,
GENERIC_READ | GENERIC_WRITE,
0,
0,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
0);
Writing:
DWORD bytesWritten = 0;
int status;
unsigned char test = 0x80;
status = WriteFile(hComm, &test, 1, &bytesWritten, NULL);
printf("Status: %d; bytesWritten: %d;n", status, bytesWritten);
I don't have anything closing the file.
I opened the file in the same way in the slave application, then used a ReadFile.
Reading:
DWORD bytesWritten = 0;
int status;
DWORD transmitCheck;
unsigned char test;
status = ReadFile(hComm, &test, 1, &transmitCheck, NULL);
Icall the CreateFile in another function I called Open_Port.cpp. In the write portion, if I set test = 0x00, up to 0x7f, the ReadFile works fine. (I was setting the values usinghex to make iteasier for me to visualize the MODBUS code) When I get to test = 0x80 = 128, test is read in as 0 on the slave side.
My goal was to have an array of characters sent, with each character containing one byte of the MODBUS code to be sent.
Thanks,
Chris
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Right now the 11.0 supports Visual Studio .NET 2003, VS2005, VS2008. VS contains a C++ compiler visual c++ (cl.exe).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You need to set number of data and stop bits as well as parity and baud rate for serial port when you open it.
It seems to me that this problem of yours is totally unrelated to Intel Compiler.
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page