01. september 2003 - 16:16
Der er
2 kommentarer og
1 løsning
Oversæt dette VB6 hvordan ?
Hej alle.
Hvordan får jeg oversat flg. til Visual Basic 6
CString strCommand; //Binary command to be executed
char arCommand[16]; //Array for the command to be executed
DCB dcb;
OVERLAPPED ovWrite;
memset(&ovWrite,0,sizeof(ovWrite));
strCommand = "10101100010100110000000000000000";//PEForward
strcpy(arCommand,strCommand);
Håber nogle kan hjælpe
01. september 2003 - 16:39
#2
Det er en del af en længere c++ kode som skal sætte nogle bit på comporten, bittene sætte i forhold til strCommand, hvis du kan/vil oversætte hele koden, vil jeg give 200 point for det.
Koden er en del af en ActiveX control, men skal "bare" være en Sub i VB
BOOL CAtmel2xCtrl::Erase()
{
MessageBox("Erase Function");
CString strCommand; //Binary command to be executed
char arCommand[16]; //Array to hold the command to be executed
DCB dcb;
OVERLAPPED ovWrite;
memset(&ovWrite,0,sizeof(ovWrite));
int nLength = 0;
m_hCommPort = CreateFile("COM1",GENERIC_READ | GENERIC_WRITE,0,NULL,
OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED |
FILE_FLAG_NO_BUFFERING,NULL);
if(m_hCommPort == INVALID_HANDLE_VALUE)
MessageBox("Error creating port. HANDLE command.");
memset(&dcb,0,sizeof(dcb));
dcb.DCBlength=sizeof(dcb);
if(!GetCommState(m_hCommPort,&dcb))
TRACE("Unable to build comm port config = '%s', err = %d\n",
(LPCTSTR)m_strBaud,GetLastError());
strCommand = "10101100010100110000000000000000"; //PE Forward
strcpy(arCommand,strCommand);
EscapeCommFunction(m_hCommPort, CLRRTS); //SCK = 0
int d;
for(d=0;d<=100000;d++)
EscapeCommFunction(m_hCommPort, SETBREAK);
//Change the state of DTR according to the command in the arCommand
while (arCommand[nLength] != '\0')
{
switch(arCommand[nLength])
{
case '0':
{
EscapeCommFunction( m_hCommPort, CLRDTR);
EscapeCommFunction(m_hCommPort,SETRTS);
//MessageBox("CLRRTS");
for(d=0;d<=50000;d++);
EscapeCommFunction(m_hCommPort,CLRRTS);
for(d=0;d<=50000;d++);
break;
}
case '1':
{
EscapeCommFunction( m_hCommPort, SETDTR);
EscapeCommFunction(m_hCommPort,SETRTS);
//MessageBox("SETRTS");
for(d=0;d<=50000;d++);
EscapeCommFunction(m_hCommPort,CLRRTS);
for(d=0;d<=50000;d++);
break;
}
}
nLength++;
}
EscapeCommFunction(m_hCommPort, CLRRTS); //SCK = 0
for(d=0;d<=100000;d++)
EscapeCommFunction(m_hCommPort, SETBREAK);
strCommand = "10101100100000000000000000000000"; //Erase Forward
strcpy(arCommand,strCommand);
nLength = 0;
//Change the state of DTR according to the command in the arCommand
while (arCommand[nLength] != '\0')
{
switch(arCommand[nLength])
{
case '0':
{
EscapeCommFunction( m_hCommPort, CLRDTR);
EscapeCommFunction(m_hCommPort,SETRTS);
//MessageBox("CLRRTS");
for(d=0;d<=50000;d++);
EscapeCommFunction(m_hCommPort,CLRRTS);
for(d=0;d<=50000;d++);
break;
}
case '1':
{
EscapeCommFunction( m_hCommPort, SETDTR);
EscapeCommFunction(m_hCommPort,SETRTS);
//MessageBox("SETRTS");
for(d=0;d<=50000;d++);
EscapeCommFunction(m_hCommPort,CLRRTS);
for(d=0;d<=50000;d++);
break;
}
}
nLength++;
}
EscapeCommFunction(m_hCommPort, CLRRTS); //SCK = 0
for(d=0;d<=100000;d++)
EscapeCommFunction(m_hCommPort, SETBREAK);
strCommand = "10101100111001100000000000000000"; //Lock bits to 11
strcpy(arCommand,strCommand);
nLength = 0;
//Change the state of DTR according to the command in the arCommand
while (arCommand[nLength] != '\0')
{
switch(arCommand[nLength])
{
case '0':
{
EscapeCommFunction( m_hCommPort, CLRDTR);
EscapeCommFunction(m_hCommPort,SETRTS);
//MessageBox("CLRRTS");
for(d=0;d<=50000;d++);
EscapeCommFunction(m_hCommPort,CLRRTS);
for(d=0;d<=50000;d++);
break;
}
case '1':
{
EscapeCommFunction( m_hCommPort, SETDTR);
EscapeCommFunction(m_hCommPort,SETRTS);
//MessageBox("SETRTS");
for(d=0;d<=50000;d++);
EscapeCommFunction(m_hCommPort,CLRRTS);
for(d=0;d<=50000;d++);
break;
}
}
nLength++;
}
//EscapeCommFunction(m_hCommPort, CLRBREAK);
CloseHandle(m_hCommPort);
MessageBox("Unit loaded without errors.");
return TRUE;