NO

Author Topic: Comm Port  (Read 24762 times)

0gmios

  • Guest
Re: Comm Port
« Reply #15 on: April 23, 2008, 06:46:16 PM »
HANDLE

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

Regards,


Offline Stefan Pendl

  • Global Moderator
  • Member
  • *****
  • Posts: 582
    • Homepage
Re: Comm Port
« Reply #17 on: April 23, 2008, 10:00:33 PM »
HANDLE is not recognised when I use it as a type...
Did you use
Code: [Select]
#include <windows.h>  ???
---
Stefan

Proud member of the UltraDefrag Development Team

0gmios

  • Guest
Re: Comm Port
« Reply #18 on: April 24, 2008, 04:07:01 AM »

Did you use
Code: [Select]
#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

  • Guest
Re: Comm Port
« Reply #19 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?

Regards,

0gmios

  • Guest
Re: Comm Port
« Reply #20 on: April 24, 2008, 06:43:42 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

  • Guest
Re: Comm Port
« Reply #21 on: April 24, 2008, 11:42:17 AM »
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...
Code: [Select]
#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,
« Last Edit: April 24, 2008, 11:46:33 AM by 0gmios »

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2115
Re: Comm Port
« Reply #22 on: April 24, 2008, 07:32:08 PM »
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

  • Guest
Re: Comm Port
« Reply #23 on: April 25, 2008, 06:20:25 AM »
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  :(

From 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...
Code: [Select]
#define WIN32_LEAN_AND_MEAN

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2115
Re: Comm Port
« Reply #24 on: April 25, 2008, 07:07:07 AM »
Quote
Example 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
« Last Edit: April 25, 2008, 07:14:43 AM by timovjl »
May the source be with you

0gmios

  • Guest
Re: Comm Port
« Reply #25 on: April 28, 2008, 03:21:59 AM »
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,
« Last Edit: April 28, 2008, 06:36:32 PM by 0gmios »

0gmios

  • Guest
Re: Comm Port
« Reply #26 on: April 28, 2008, 08:35:22 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