praca na rs232

0

Witam.
Pracuje nad napisaniem programu ktory bedzie wykorzystywal port com do obslugi modemu gsm.
Korzystam z ms visual c++ 6.0 i problem polega na tym, ze kompilacja ponizszego kodu:

#include <string.h>
#include <iostream.h>
#include <Winbase.h>
#include <Windows.h>

char szPortName[] = "com1";

HANDLE m_hCommPort = CreateFile( szPortName,
GENERIC_READ|GENERIC_WRITE, // access ( read and write)
0, // (share) 0:cannot share the
// COM port
0, // security (None)
OPEN_EXISTING, // creation : open_existing
FILE_FLAG_OVERLAPPED, // we want overlapped operation
0 // no templates file for
// COM port...
);

GetLastError ();

Wywala 74 bledy typu:
c:\program files\microsoft visual studio\vc98\include\winbase.h(216) : error C2146: syntax error : missing ';' before identifier 'Internal'
c:\program files\microsoft visual studio\vc98\include\winbase.h(216) : error C2501: 'DWORD' : missing storage-class or type specifiers
c:\program files\microsoft visual studio\vc98\include\winbase.h(216) : error C2501: 'Internal' : missing storage-class or type specifiers
c:\program files\microsoft visual studio\vc98\include\winbase.h(217) : error C2146: syntax error : missing ';' before identifier 'InternalHigh'
c:\program files\microsoft visual studio\vc98\include\winbase.h(217) : error C2501: 'DWORD' : missing storage-class or type specifiers
c:\program files\microsoft visual studio\vc98\include\winbase.h(217) : error C2501: 'InternalHigh' : missing storage-class or type specifiers

Co moze byc tego powodem? Sa jakies inne metody na obsluge rs232?

DARO
[email protected]

0

Zapewne się mylę, ale zobacz czy zamiana kolejności inkludów (2 ostatnie) pomoże.

0

Nie wiem, ale moze musisz wypelnic strukture DCB. Kiedys napisalem klase do obslugi COM'ow, zmieniajaca napiecie w pinie DTR, moze Ci sie przyda:

#include <windows.h>

class com1
{
public:
	com1();
	~com1();

	HANDLE hNumPort;
	bool swieci;
	bool istnieje;

	bool zaswiec();
	bool zgas();
	void ini();
	void del();
};
#include "com.h"

//--------------------------------------------------------------

com1::com1()
{
	istnieje=false;
	swieci=false;
}

//--------------------------------------------------------------

com1::~com1()
{
	if(istnieje) CloseHandle(hNumPort);
}

//--------------------------------------------------------------

bool com1::zaswiec()
{
	if(swieci==false && istnieje) EscapeCommFunction(hNumPort, SETDTR);
	swieci=true;
	return true;
}

//--------------------------------------------------------------

bool com1::zgas()
{
	if(swieci==true && istnieje) EscapeCommFunction(hNumPort, CLRDTR);
	swieci=false;
	return true;
}

//--------------------------------------------------------------

void com1::ini()
{
	if(!istnieje)
	{
		//inicjalizacja portu com1
		DCB dcb;
		hNumPort = CreateFile("COM1", GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
		dcb.DCBlength  = sizeof(dcb);
		dcb.BaudRate   = CBR_9600;
		dcb.fParity       = FALSE;
		dcb.Parity        = NOPARITY;
		dcb.StopBits     = ONESTOPBIT;
		dcb.ByteSize     = 8;
		dcb.fDtrControl = DTR_CONTROL_ENABLE;
		dcb.fRtsControl = RTS_CONTROL_DISABLE;
		dcb.fOutxCtsFlow     = FALSE;
		dcb.fOutxDsrFlow     = FALSE;
		dcb.fDsrSensitivity   = FALSE;
		dcb.fAbortOnError    = FALSE;
		dcb.fOutX = FALSE;
		dcb.fInX = FALSE;
		dcb.fErrorChar = FALSE;
		dcb.fNull = FALSE;
		SetCommState(hNumPort, &dcb);
		EscapeCommFunction(hNumPort, CLRDTR);
	}
	istnieje=true;
	swieci=false;
}

//--------------------------------------------------------------

void com1::del()
{
	if(istnieje) CloseHandle(hNumPort);
	istnieje=false;
}

1 użytkowników online, w tym zalogowanych: 0, gości: 1