Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
accessing Virtual COM ports with FB...?
#1
Are you able to access a virtual com port with FB? I have a GPS reciver that uses a USB interface and is installed on windows as COM3. I would like to access the data from it but don't know how as COM3 doesn't have a real address as such.

Cheers Big Grin
Reply
#2
afaik on windows you can't talk directly to coms from an application.
but there are special dll's you can use like winio.dll.
your app talks to the dll and the dll to the coms.
Reply
#3
That's impossible to do on Win NT w/o a device driver, as fsw said. User-mode applications can't directly access IO ports like used to be allowed in Win9x days anymore.
Reply
#4
Actually, if i remember correctly. You can access them with windows file routines. Something like that. I don't entirely remember.
oship me and i will give you lots of guurrls and beeea
Reply
#5
I looked more into it, and Blitz is right.
It's seems possible to use serial comms like files with:
hWndCOMM = CreateFile_("COM1:",GENERIC_READ OR GENERIC_WRITE , 0, NULL, OPEN_EXISTING, 0, NULL)

Use GetCommState to retrieve the comm settings and SetCommState to set them.
If you have to set the timeouts use SetCommTimeouts.
The buffers are set with SetupComm.
Close the comm port with CloseHandle(hWndCOMM).

Hope this gets you going...
Reply
#6
Yes, serial ports are managed thru CreateFile, WriteFile and ReadFile. I hacked a Delphi comms library and this is how it's done. Unftyunately the code was to OOP'ish to be easily translated to FB

I tried to do a small demo.I switched to C, for if it was something in wrong FB..
It should make a 3M USRobotics 56Kfaxmodem answer the parameter table.
can someone tell me why it does'nt work?

Code:
#include<windows.h>
#include<string.h>
#include<stdio.h>
#include<time.h>
DCB dcb;
HANDLE hcom;
COMSTAT comstat;
COMMTIMEOUTS commtimeouts;
BOOL fsuccess;
unsigned long  int num,errs;
char  tx[]="ATI4\x13" ;
char rx[2000];
char  pcommport[]="\\\\.\\COM1";
char a;
time_t t;

int main()
{
hcom=CreateFile(pcommport,GENERIC_READ|GENERIC_WRITE,0,NULL,OPEN_EXISTING,0,NULL);
if (hcom==INVALID_HANDLE_VALUE)
{
   printf( "Failure opening port %d",hcom);
   return(1);
}
else
   printf("port opened %d\n",hcom);

fsuccess=SetupComm(hcom, 2048, 2048);

fsuccess=GetCommState(hcom,&dcb);
if (fsuccess==0)
{
   printf( "Failure getting port config %d",fsuccess);  
    fsuccess=CloseHandle(hcom);
     return(2);  
}
else
  printf( "Success getting port config\n ");
dcb.DCBlength=sizeof(DCB);
dcb.fOutxDsrFlow=FALSE;  
dcb.fOutxCtsFlow=FALSE;
dcb.fDtrControl=DTR_CONTROL_DISABLE;
dcb.fRtsControl=RTS_CONTROL_DISABLE;
dcb.fOutX=FALSE;
dcb.fInX=FALSE;
dcb.BaudRate=CBR_9600;
dcb.ByteSize=7;
dcb.Parity=ODDPARITY;
dcb.StopBits=ONESTOPBIT;

fsuccess=SetCommState(hcom,&dcb);
if (fsuccess==FALSE)
{
   printf( "Failure setting port config %d",fsuccess);  
   fsuccess=CloseHandle(hcom);
   return(3);  
}else
   printf( "Success setting port config\n");  


fsuccess=FlushFileBuffers(hcom);

fsuccess=GetCommTimeouts(hcom,&commtimeouts);
commtimeouts.ReadIntervalTimeout=2;
commtimeouts.ReadTotalTimeoutMultiplier=1;
commtimeouts.ReadTotalTimeoutConstant=20;
commtimeouts.WriteTotalTimeoutMultiplier=1;
commtimeouts.WriteTotalTimeoutConstant=20;
fsuccess=SetCommTimeouts(hcom,&commtimeouts);

{
  

  fsuccess=WriteFile(hcom,&tx,strlen(tx),&num,0);
  if (fsuccess==FALSE) printf("\nError writing to port");
  
  t=time(0); do; while (difftime(time(0),t)<2);
  fsuccess=ReadFile(hcom,&rx,80,&num,0);
  if (fsuccess==FALSE) printf("\nError reading port");
  printf("%d  > %s\n",num,rx);
}
fsuccess=CloseHandle(hcom);  
printf ("\nExiting. Press a key");
a=getchar();
return(0);
}
Antoni
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)