Help in communication PC through Parallel port

Do you have a question? Post it now! No Registration Necessary

Translate This Thread From English to

Threaded View
Hello,

 This is a sample code to communicate with 2 pcs thro the
parallel(LPT1) port. We were successful in creating a Handle and also
set a timeout value for the port. But when i try writing to the
parallel port write is unsuccessful and the error value is
1167(ERROR_DEVICE_NOT_CONNECTED - The device is not connected. ). Can
someone explain what this error means and what could be done to
resolve this. I am using VC++ 6.0 on a win2k pc with 64mb of ram.
 The dest Pc is running on Win98. On this PC, CreateFile fails with an
error code  of 2250(ERROR_NOT_CONNECTED - This network connection does
not exist. ). Please elaborate in case any details are available.
 

 
 /**************************************/
HANDLE parallel1 ;
DCB DCBStruct;
memset(&DCBStruct,0,sizeof(DCB));
char buffer1[65536],buffer2[65536] ;
memset(buffer1,0xAA,65536);
memset(buffer2,0x66,65536);
unsigned long out;
char sztemp[50];
COMMTIMEOUTS  timeout;
/******************************************/
DCBStruct.DCBlength = 28 ;
DCBStruct.BaudRate = CBR_256000;
DCBStruct.fBinary = 1 ;
DCBStruct.fParity = 1 ;
DCBStruct.ByteSize = 8;
DCBStruct.StopBits = ONESTOPBIT ;
/******************************************/
parallel1 = CreateFile("LPT1",
GENERIC_WRITE,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_ALWAYS,0,NULL);
int i = GetLastError();
i = (int )INVALID_HANDLE_VALUE ;
if(i != 0 )
{
 sprintf(sztemp,"Creating Error:%d",i);
 AfxMessageBox(sztemp);
}
else
{
//  SetCommState(parallel1,&DCBStruct);
//  GetCommTimeouts(parallel1,&timeout);
 timeout.ReadIntervalTimeout = 1 ;
 timeout.ReadTotalTimeoutConstant = 1 ;
 timeout.ReadTotalTimeoutMultiplier = 1 ;
 timeout.WriteTotalTimeoutMultiplier = 1;
 timeout.WriteTotalTimeoutConstant = 3000 ;////////culprit
 SetCommTimeouts(parallel1,&timeout);
 i = GetLastError();
 if(i != 0)
 {
  sprintf(sztemp,"Set Timeout Err:%d",i);
  AfxMessageBox(sztemp);
 }
//  for(int i = 0 ; i < 3 ; i++)
 {
//   WriteFile(parallel1,buffer1,65536,&out,NULL);
  WriteFile(parallel1,buffer1,10,&out,NULL);
  i = GetLastError();
  sprintf(sztemp,"out : %d, err is %d",out,i);
  AfxMessageBox(sztemp);
  WriteFile(parallel1,buffer2,10,&out,NULL);
  sprintf(sztemp,"out : %d, err is %d",out,i);
  AfxMessageBox(sztemp);
 }
 CloseHandle(parallel1);
}
/*************************************/
 
 
waiting for reply
praveen

Re: Help in communication PC through Parallel port

: Hello,
:
:  This is a sample code to communicate with 2 pcs thro the
: parallel(LPT1) port. We were successful in creating a Handle and also
: set a timeout value for the port. But when i try writing to the
: parallel port write is unsuccessful and the error value is
: 1167(ERROR_DEVICE_NOT_CONNECTED - The device is not connected. ). Can
: someone explain what this error means and what could be done to
: resolve this. I am using VC++ 6.0 on a win2k pc with 64mb of ram.
:  The dest Pc is running on Win98. On this PC, CreateFile fails with an
: error code  of 2250(ERROR_NOT_CONNECTED - This network connection does
: not exist. ). Please elaborate in case any details are available.

    Moderately off-topic here, but........

    Both computres must have a birectional parallel port.
    Both computers must have CMOS set properly.  (ECP/EPP..)
    The Cable must be a bidirectional cable (Thick, not the thin ones)
    Serial communication is easier.




Site Timeline