473,385 Members | 1,898 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How to write a C++ program to record the Serial Port I/O traffic?

Hi All,

Anyone know know to write a C++ program that able to record all the data that send to and receive from device through Serial Port (COM1)?
Dec 1 '06 #1
7 21183
Banfa
9,065 Expert Mod 8TB
Which program is doing the sending an receiving? The program you are going to write?

If not then this is not an easy task and may be impossible because in general a serial port can only be owned by 1 application at a time so the application sending an receiving the data will be the one that owns the port and you will not be able to see what is happening.
Dec 1 '06 #2
horace1
1,510 Expert 1GB
Hi All,

Anyone know know to write a C++ program that able to record all the data that send to and receive from device through Serial Port (COM1)?
probably the simplest way is to to tap into the serial cable bewteen the devices and take a line into another serial port (on another PC?} which can listen to one side of the communications (or into two serial ports to listen to both side)

a cable something like
http://www.rs232pro.com/rs232/half_duplex.htm
or you could make one - all you need is three 9 pin D-type connectors and some cable

or you could use a RS232 break out box
http://www.lashen.com/products/tools/CZ_32-122.asp
Dec 1 '06 #3
Thanks banfa & Horace1,
I get what u guys mean, so there is no way to trace the RS232 communication data? My condition is, my PC is connected to a printer, and i want to know what data are sent n received by my PC, any idea of creating C++ software to do this?
Dec 6 '06 #4
probably the simplest way is to to tap into the serial cable bewteen the devices and take a line into another serial port (on another PC?} which can listen to one side of the communications (or into two serial ports to listen to both side)

a cable something like
http://www.rs232pro.com/rs232/half_duplex.htm
or you could make one - all you need is three 9 pin D-type connectors and some cable

or you could use a RS232 break out box
http://www.lashen.com/products/tools/CZ_32-122.asp
Hi Horace1,

I tried to compile the code you post in topic "reading data from barcode reader" http://www.thescripts.com/forum/thread569742.html

and i found this error:
1>.\a.cpp(26) : error C2664: 'CreateFileW' : cannot convert parameter 1 from 'char [5]' to 'LPCWSTR'

from:
hCom = CreateFile(ComPortName, GENERIC_READ | GENERIC_WRITE,
0, // exclusive access
NULL, // no security
OPEN_EXISTING,
0, // no overlapped I/O
NULL); // null template

do you know what it is? i'm using visual studio C++ on windows XP.
Dec 6 '06 #5
Hi Banfa n horace1,

I'm going to use another PC to read the data transfered between a PC and a printer, i'm using COM1 & COM2:
COM1 will read the data sent by PC to printer
COM2 will read the data sent by printer to PC

Do you have a program doing this, or any idea of doing this?
I'm using VS C++ on windows XP, and I'm beginner in programming. Thanks for your help. Really appreciate it.
Dec 6 '06 #6
horace1
1,510 Expert 1GB
Hi Banfa n horace1,

I'm going to use another PC to read the data transfered between a PC and a printer, i'm using COM1 & COM2:
COM1 will read the data sent by PC to printer
COM2 will read the data sent by printer to PC

Do you have a program doing this, or any idea of doing this?
I'm using VS C++ on windows XP, and I'm beginner in programming. Thanks for your help. Really appreciate it.
I don't use Visual C so have no direct experience of using serial IO with it.

When I did a google search on "visual C++ serial IO" it turned up a list of useful looking links with example serial IO code which you should be able to adapt
Dec 6 '06 #7
ajain
9
hey i'v been working on serial com port for quiet some time. use the bioscom and _bios_serialcom, with them u can actually monitor the status of any of the COM ports...here is a c program to do tht...c if it proves to b of some help in ur c++ code.do change ur device adress...


Expand|Select|Wrap|Line Numbers
  1. #include<stdio.h>
  2. #include<conio.h>
  3. #include<bios.h>
  4. #include<time.h>
  5. #include<dos.h>
  6.  
  7.  
  8. #define COM1 0x03F8
  9. #define COM2 0x02F8
  10. #define DATA_READY 0X60B0
  11. #define SETTINGS (_COM_9600|_COM_NOPARITY|_COM_STOP1|_COM_CHR8)
  12.  
  13.     int start_addr();
  14.     int end_addr();
  15.     void group_addr();
  16.     void display_time();
  17.     void transmit_frame(int*,int*);
  18.     void recieve_frame(int*);
  19.  
  20.  
  21.     void main(void)
  22.  
  23.     {
  24.          char send;
  25.          int abyte,in;
  26.          int a,b,c,r,addr,status;
  27.          unsigned int ret_value;
  28.          int count, arr[6];
  29.          int bit_num,s_addr, e_addr;
  30.          int parity, baud,port,mode;
  31.          int com_port_no,stop_bit;
  32.          char abyte_stopbit, abyte_baud, abyte_parity,abyte_databit;
  33.          char arr_baud[]= {0x00, 0x20, 0x40, 0x60,0x80,0xA0,0xC0,0xE0};;
  34.  
  35.          clrscr();
  36.  
  37.           //COM PORT SELECT SETTINGS//
  38.          printf("\nSelect COM Port\nCOM 1\nCOM 2\n");
  39.          scanf("%d",&com_port_no);
  40.          switch(com_port_no)
  41.             {
  42.              case 1:port = 0;
  43.                 break;
  44.  
  45.              case 2:port =1;
  46.                 break;
  47.             }
  48.  
  49.  
  50.                         //TRANSMISSION MODE//
  51.                   clrscr();
  52.                  addr = start_addr();
  53.                  printf("\nESC to exit\n");
  54.                 // for(;;)
  55.  
  56.                     {
  57.                 transmit_frame(&addr,&port);
  58.                     delay(5);
  59.                     printf("\n");
  60.                     recieve_frame(&port);
  61.                     }
  62.                   printf("\n");
  63.  
  64.  
  65.  
  66.  
  67.         getch();
  68.  
  69.         }
  70.  
  71.      void transmit_frame(int*addr,int*port)
  72.         {
  73.  
  74.          unsigned int in;
  75.          int trans,i;
  76.          char arr[] = {0x01};
  77.  
  78.  
  79.  
  80.          if(kbhit())
  81.             {
  82.                if(getch()=='\x1B')
  83.                 { exit(0);
  84.                 }
  85.             }
  86.          else
  87.             {
  88.                 trans = arr[0];
  89.                 printf("%x ",trans);
  90.                 _bios_serialcom(_COM_SEND,*port, trans);
  91.                 delay(100);
  92.             }
  93.  
  94.         }
  95.  
  96.  
  97.  
  98.     void recieve_frame(int*port)
  99.         {int v;
  100.         int trans;
  101.  
  102.         unsigned int status,out;
  103.      {
  104.        status = _bios_serialcom_COM_STATUS,*port,SETTINGS);
  105.        printf("%x",status);
  106.  
  107.               out=_bios_serialcom(_COM_RECEIVE,*port,0);
  108.               trans = out;
  109.               printf("\n%x",trans);
  110.  
  111.  
  112.  
  113.          }
  114.  
  115.          }
  116.  
  117.     start_addr()
  118.         {int s_addr1;
  119.         printf("\nStart Address:");
  120.         scanf("%x",&s_addr1);
  121.         return(s_addr1);
  122.         }
  123.  
  124.  
Dec 10 '06 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

13
by: Bob Greschke | last post by:
We have some equipment that communicates at 57600 baud RS232. The path from the PC is USB to a Phillips USB hub, then off of that a TUSB3410 USB/Serial converter. The driver for the 3410 chip...
4
by: Tom Van Ginneken | last post by:
Hi, I need to write binary data to a serial port. I am using this function: #include <unistd.h> ssize_t write(int fd, const void *buf, size_t count); I am able to write a alpha-numeric...
3
by: collinm | last post by:
hi i send a command to a led display, the led display is suppose to return me some character i write a string on a serial port void ledDisplayExist() { char msg={'\0', '\0', '\0', '\0',...
5
by: Confused User | last post by:
I am working on device that utilizes a Motorola 68HC16 microcontroller. I am using an old unsupported piece of crap Whitesmith's / Intermetrics / Tasking compiler. The embedded compiler business...
2
by: Alvin Lau | last post by:
Can I write pocket PC bluetooth program by using C# ? It seems so difficult to find the library? If it is possible , where can i find the reference of these kind of program ? *** Sent via...
1
by: kiran | last post by:
Hi all, I have a problem to communicate with serial port(COM3:). I am able to open the handle but cannot send any data. 1. I connected my motoroala handset to PC through datacable. 2. I...
0
by: Tom | last post by:
I am new to hardware programming. I need to write a program for reading data from Card Reader which connects to the PC windows 2000/XP OS through Interfacing The Serial / RS-232 Port / USB /...
6
by: Ken | last post by:
When running a program in the debugger, what would cause it to crash without any error messages? I get "The program has exited with code 0 (0x0)". The program is a MDI app with threading for...
3
by: John Dann | last post by:
Trying to learn Python here, but getting tangled up with variable scope across functions, modules etc and associated problems. Can anyone advise please? Learning project is a GUI-based...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.