Serial Port Programming

Posted on 2006-04-25
Last Modified: 2012-05-05
Hi, i have written an app that writes a datastring to the comm port every second. When i used the monitoring ultility provided by the multi port board appears..that the port has been successfully opened and data are transmitting. But my device don't seems to be acting upon receiving the data...... Anyway maybe i could have the datastring format screwed up.

Here's the datastring format given

<STX><POL><5 byte Ascii data><Space><PCS><CR><LF>

STX is chr(12),
POL which is either -ve or +ve...which is always chr(43) in my case
5 byte Ascii Data - i hardcoded it to be 55555
Space which is chr(32)
PCS which are 3 bytes chr(80), chr(67) and chr(83)
CR - return carriage chr(13)
LF - LineFeed chr(10)

In my code...i put it as

myValue = 55555
str_tx = chr(12) & chr(43) & myValue & chr(32) & chr(80) & chr(67) & chr(83) & _
            chr(13) & chr(10)

I am not sure if it is the way present my datastring.... By the way....if i were to type to above string using do i present it? like? STX+55555 PCS
what about the CR and LF and space character when testing it with hyperterminal?
Question by:jaxrpc
    LVL 48

    Expert Comment

    I used this program to talk with COM port in binary mode:

    This is my question with additional information:

    You need to find also some COM port sniffer and to test what data is sent by your program. I don't think that using string variable is right way. Use Byte array instead.

    Author Comment

    yup actually the data i sent in bytes...btyeArrary() = Encoding.ASCII.GetBytes(str_Tx)  
    LVL 48

    Accepted Solution

    Test GetBytes return value in debugger. I am not sure that 55555 gives 5 bytes, each one is 5 (BTW, should it be 5 or '5'?). I think that this is better to work directly with Byte array.
    Using program mentioned in my first post, get device working. You can set COM port parameters and send bytes giving their values as Hex numbers, and read device reply. Only when you see that device is really working and responds as expected, try to do the same with your program. This is standard to make such programs - in your current state, you don't know whether your program is wrong, or device is not working, or cable is not working, or you are using incorrect port settings.

    Author Comment

    I see...the link u gave is not working.... anyway what's the name of the program? maybe it is still available somewhere on the net.
    LVL 48

    Expert Comment

    I can post you this program name later, it is kept on one of my CDs, I don't have it here right now.
    You can save your time asking this question in Programming and Hardware areas (give also link in the C area). Generally, you need program like Hyper Terminal, which can work with COM port (additional options like sockets are not required), and allows to type and read binary information.

    Author Comment

    thanks...sorry but if i were to use the hyperterminal to test the textArea how do i present my dataString? Like ...... just simply type STX+12345 PCSCRLF ??
    Sorry i am really new to this....and i am also not good with bits and bytes
    LVL 48

    Expert Comment

    I have never try to work with Hyper Terminal in binary mode. Usually I am working with COM port with my own program, written in C++. I also successfully worked with another program, but link to it is not working now.
    You will not find many programmers who know communications here in VB .NET area. I suggest you to ask questions which are not related to VB, in C and C++ areas. Real time programmers can help you to fix many problems except your code in VB.
    I will post program name later.

    Expert Comment

    You can try out those tools
    Really useful to me for every serial communication aspect

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
    Article by: jpaulino
    XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String ( Literal, only instead of starting and ending with w…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
    This video discusses moving either the default database or any database to a new volume.

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now