News:

Download Pelles C here: http://www.smorgasbordet.com/pellesc/

Main Menu

Comm Port

Started by 0gmios, April 22, 2008, 05:43:24 AM

Previous topic - Next topic

0gmios

Quote from: timovjl on April 23, 2008, 10:40:48 AM
HANDLE

HANDLE is not recognised when I use it as a type...

Regards,


Stefan Pendl

Quote from: 0gmios on April 23, 2008, 06:46:16 PMHANDLE is not recognised when I use it as a type...
Did you use #include <windows.h>  ???
---
Stefan

Proud member of the UltraDefrag Development Team

0gmios

Quote from: Stefan Pendl on April 23, 2008, 10:00:33 PM

Did you use #include <windows.h>  ???


No. I have never had to do anything that has included windows.h (didn't even know it existed).

Thanks, I will have a look at the code above again

Regards,

0gmios

Okay, just by including windows.h I got over 100 errors, and if that wasn't bad enought it insulted me saying "please improve yourself"  :'(

It also says "If you are compiling a Windows program: make sure you use the /Ze option!"

How do I do this?

Regards,

0gmios

Quote from: 0gmios on April 24, 2008, 04:13:10 AM
Okay, just by including windows.h I got over 100 errors, and if that wasn't bad enought it insulted me saying "please improve yourself"  :'(

It also says "If you are compiling a Windows program: make sure you use the /Ze option!"

How do I do this?

I found it... I wasn't clicking the compiler tab in project options... Then there it was, a simple check box... Fool!

0gmios

#21
I think it is working, but I am having some security issues trying to access the port (I need to test on another machine at home). The new machines we are using won't even let me access the printer port with _outp and _inp. I use userport (http://www.writelog.com/support/lpt_port_support_on_windows_nt.htm) to grant direct access to the ports, its just not working on the current machines...  >:(

I also did this to send text to the serial port. But I cant receive text...
#include <stdio.h>
#include <stdlib.h>

void main(void)
{
    int menuoption = 0;

    for(;;) //forever
    {
        system("cls");
        printf (" 1  Turn LED on \n");
        printf (" 2  Turn LED off \n");
        printf (" 3  Exit \n");
        printf (" Select Option and RETURN \n");

        scanf("%d", &menuoption);

        if (menuoption == 1)
            system("echo led on > com3");
        if (menuoption == 2)
            system("echo led off > com3");
        if (menuoption == 3)
            break;
    }
}

The system command was quite helpful. I can control all of the outputs using this, but like I said I cannot receive text with it to read the inputs  :(

Regards,

TimoVJL

Example converted to use Win32 API.
It doesn't send CR+LF.

From here you found virtual com port.
http://com0com.sourceforge.net/
May the source be with you

0gmios

Quote from: timovjl on April 24, 2008, 07:32:08 PM
Example converted to use Win32 API.
It doesn't send CR+LF.

Have no idea what that means.

But thanks for the zip file. Unfortunitly it is a public holiday here in Australia, so work is closed, and I don't have a serial port interface at home to test  :(

Quote from: timovjl on April 24, 2008, 07:32:08 PMFrom here you found virtual com port.
http://com0com.sourceforge.net/

Thanks, I will have a look at this.

Regards,

P.S. What is with the...
#define WIN32_LEAN_AND_MEAN

TimoVJL

#24
QuoteExample converted to use Win32 API.
It doesn't send CR+LF.
It means that you have to send them ("\r\n") if linefeed is needed for device.

With com0com you can open virtually connected port (CNCB0) with HyperTerminal to see what you application send to CNCA0.
Open it as "\\\\.\\CNCA0".

Paired ports are CNCA0 <-> CNCB0 by default but those names can be changed to COMx with com0com setup program.

http://com0com.sourceforge.net/doc/UsingCom0com.pdf
May the source be with you

0gmios

#25
Yeah gees thanks timovjl, that's great I just wasted a $100 on a book with source code which I don't need because your tiny piece of code works so well  ;D

Thanks. I am going through a winAPI tutorial from http://forum.pellesc.de/index.php?topic=2105.0 and MSDN to try and understand all the components of the code.

The text book will still be a useful resource for leaning more about all of this, so I don't actually think that it is a waste of money.

Regards,

0gmios

Quote from: timovjl on April 25, 2008, 07:07:07 AM
It means that you have to send them ("\r\n") if linefeed is needed for device.

BTW, yes I need to include either \n or \r for the command to work (hence I added an extra byte to each command - led on 6 bytes, led on \n, 7 bytes).

I recommend you add your code to http://forum.pellesc.de/index.php?topic=1272.0. So other people get the same benifit I did. I would like to add it, but it is your code...

Regards,

Graham