How can I control the serial port?

Hello to everyone.Iam dealing with a project these days about controling a robot through internet.The basic idea is to create a cgi script to control the serial port(i have to sent some chars there as commands for the robot) but i'm afraid i 'm facing problems.I would be grateful if someone could help me and tell me how to sent chars in serial.I've tried the bioscom function from bios.h but the robot is not responding.Iam not sure though that i did everything right.
Thank you

Comments

  • : Hello to everyone.Iam dealing with a project these days about controling a robot through internet.The basic idea is to create a cgi script to control the serial port(i have to sent some chars there as commands for the robot) but i'm afraid i 'm facing problems.I would be grateful if someone could help me and tell me how to sent chars in serial.I've tried the bioscom function from bios.h but the robot is not responding.Iam not sure though that i did everything right.
    : Thank you
    :

    Check out this post if you are using Windows:
    http://www.programmersheaven.com/c/MsgBoard/read.asp?Board=258&MsgID=227271

    or search for either "serial port" or "rs232" on this board, there are plenty of posts about this topic.
  • Thanx a lot man!I will follow your advice!U know I;m always saying JAG ELSKA SVERIGE!
  • hmm..Unfortunately i tried to compile the programm written in the post you mentioned but it contains more than 20 errors...Time for some serius debugging...Thanx anyway!!
  • : hmm..Unfortunately i tried to compile the programm written in the post you mentioned but it contains more than 20 errors...Time for some serius debugging...Thanx anyway!!
    :

    It was just an example, not runable code. You will have to modify it.

  • : Hello to everyone.Iam dealing with a project these days about controling a robot through internet.The basic idea is to create a cgi script to control the serial port(i have to sent some chars there as commands for the robot) but i'm afraid i 'm facing problems.I would be grateful if someone could help me and tell me how to sent chars in serial.I've tried the bioscom function from bios.h but the robot is not responding.Iam not sure though that i did everything right.
    : Thank you
    :


    I've been using the parallel port to control things by placing data directly on the individual pins. It gives me more pins to work with. My programming is probably not up to professional standards and I'm sure it can be written cleaner, but I studied my way through to a solution. I use the following code in Win32 written with Borland C++ 4.52 to control the bits of the Parallel port. The cable used also has to have three jumpers on the computer end to tell the OS that it is operational. These jumpers are: Pin 1 to pin 10, Pin 11 to pin 12 to pin 25, and pin 13 to pin 15. I also buffer the signals through a 74HCT540 for my use. You may not want to connect the parallel port directly to your robot. You should be able to study the following routine and rewrite it to allow reading some of the pins if you want to bring in states from the robot.

    [code]

    char signalByte[2] = " "; // I place different values here based on which pins to set/reset


    void TBEWindow::CmSendByte()
    {
    DWORD bytes;
    COMMTIMEOUTS ctmoNew = {0}, ctmoOld;
    HANDLE hSendByte = CreateFile("LPT1", GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0);
    if (hSendByte != INVALID_HANDLE_VALUE)
    {
    GetCommTimeouts(hSendByte,&ctmoOld);
    ctmoNew.ReadIntervalTimeout = MAXDWORD;
    ctmoNew.ReadTotalTimeoutConstant = 0;
    ctmoNew.ReadTotalTimeoutMultiplier = 0;
    ctmoNew.WriteTotalTimeoutMultiplier = 100;
    ctmoNew.WriteTotalTimeoutConstant = 100;
    SetCommTimeouts(hSendByte, &ctmoNew);
    WriteFile(hSendByte, signalByte, 1, &bytes, 0);
    SetCommTimeouts(hSendByte, &ctmoOld);
    CloseHandle(hSendByte);
    }
    }
    [/code]

    Take Care,
    Ed Hall

  • :
    : : Hello to everyone.Iam dealing with a project these days about controling a robot through internet.The basic idea is to create a cgi script to control the serial port(i have to sent some chars there as commands for the robot) but i'm afraid i 'm facing problems.I would be grateful if someone could help me and tell me how to sent chars in serial.I've tried the bioscom function from bios.h but the robot is not responding.Iam not sure though that i did everything right.
    : : Thank you
    : :
    :
    :
    : I've been using the parallel port to control things by placing data directly on the individual pins. It gives me more pins to work with. My programming is probably not up to professional standards and I'm sure it can be written cleaner, but I studied my way through to a solution. I use the following code in Win32 written with Borland C++ 4.52 to control the bits of the Parallel port. The cable used also has to have three jumpers on the computer end to tell the OS that it is operational. These jumpers are: Pin 1 to pin 10, Pin 11 to pin 12 to pin 25, and pin 13 to pin 15. I also buffer the signals through a 74HCT540 for my use. You may not want to connect the parallel port directly to your robot. You should be able to study the following routine and rewrite it to allow reading some of the pins if you want to bring in states from the robot.
    :
    : [code]
    :
    : char signalByte[2] = " "; // I place different values here based on which pins to set/reset
    :
    :
    : void TBEWindow::CmSendByte()
    : {
    : DWORD bytes;
    : COMMTIMEOUTS ctmoNew = {0}, ctmoOld;
    : HANDLE hSendByte = CreateFile("LPT1", GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0);
    : if (hSendByte != INVALID_HANDLE_VALUE)
    : {
    : GetCommTimeouts(hSendByte,&ctmoOld);
    : ctmoNew.ReadIntervalTimeout = MAXDWORD;
    : ctmoNew.ReadTotalTimeoutConstant = 0;
    : ctmoNew.ReadTotalTimeoutMultiplier = 0;
    : ctmoNew.WriteTotalTimeoutMultiplier = 100;
    : ctmoNew.WriteTotalTimeoutConstant = 100;
    : SetCommTimeouts(hSendByte, &ctmoNew);
    : WriteFile(hSendByte, signalByte, 1, &bytes, 0);
    : SetCommTimeouts(hSendByte, &ctmoOld);
    : CloseHandle(hSendByte);
    : }
    : }
    : [/code]
    :
    : Take Care,
    : Ed Hall
    :
    :

    If you only need 9 pins (or 2 pins, which is most common) there is no reason to choose parallell port. That port is also removed from newer computers.

  • I'm afraid i'm in a dead end.I can't use the parallel port as you advised.The nature of my project demands the use of the serial port.
    I'm trying this code but the robot is not responding.
    int DONE=0;
    char *str, *cmd;

    cmd="TH";

    bioscom(0,SETTINGS,COM1);
    while(DONE!=1){
    if (kbhit()){
    bioscom(1, cmd, COM1);
    str=getche();
    if(str==27) DONE=1;
    The funny is that i managed to communicate with a programm in qbasic but i need c for the cgi scripts.
  • Please take all my info with the appropriate critique. I'm not that familiar with serial communications. It looks to me, studying the code you've shown, that you are trying to send two characters at once (cmd="TH";). My understanding is that only one byte can be passed for a call to bioscom(). Additionally, it seems that the same value is to be passed no matter what you press on the keyboard (other than ESC). You might try initializing cmd to a single character and placing the getche() value into it to send. Perhaps you meant: bioscom(1, str, COM1); to send the keyboard byte.

    Take Care,
    Ed Hall

    : I'm afraid i'm in a dead end.I can't use the parallel port as you advised.The nature of my project demands the use of the serial port.
    : I'm trying this code but the robot is not responding.
    : int DONE=0;
    : char *str, *cmd;
    :
    : cmd="TH";
    :
    : bioscom(0,SETTINGS,COM1);
    : while(DONE!=1){
    : if (kbhit()){
    : bioscom(1, cmd, COM1);
    : str=getche();
    : if(str==27) DONE=1;
    : The funny is that i managed to communicate with a programm in qbasic but i need c for the cgi scripts.
    :

  • : : hmm..Unfortunately i tried to compile the programm written in the post you mentioned but it contains more than 20 errors...Time for some serius debugging...Thanx anyway!!
    : :
    :
    : It was just an example, not runable code. You will have to modify it.
    :

    To compile that example you need a modern 32-bit compiler that can compile Windows programs. you can get a free compiler at www.bloodshed.net if you need it.
  • Well I have to admit that you have a point about the two characters at once.Unfortunatelly i tried it one at a time and nothing happened.About the ESC I did'nt actually used that part of the code.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories