Isso exatamente isso,quero me comunicar com o arduino com ele conectado ao computador e eu mandar instruções a ele.
Eu vi um dos links,utilizando o VB,mas os links que baixei não consegui importar no vb,ja no c++ eu tentei algumas coisas mas tambem sem sucesso.
sobre o builder,arilson eu queria não o builder mas um com que eu pudesse criar uma "boa imagem" para o programa,botoes e etc.
Sobre a lib firmadata eu não entendi muito bem,mas pelo que parece é a mais recomendada não ? procurei alguns topicos,mas tb sem sucesso de pelo menos acender um led em c++/vb ou qualquer outra linguagem com que eu possa utilizar de ferramentas como botões,box,etc
Agradeço a ajuda de vcs,garanto que clareou minha mente quanto ao meu projeto,mas se por favor alguem tiver algum codigo de por exemplo acender um led usando essas linguagens eu agradeço.
Tentei este,mas deu muito erro>>>
No arduino
int ledPin = 13; // LED connected to digital pin 13 ledPin int = 13; / LED conectado ao pino digital 13
int val=0; // Byte received val int = 0; / / Byte recebido
int bytesread = 0; // Number of bytes received counter bytesRead int = 0; / / Número de bytes recebidos contador
char code[20]; // Hold up to 20 Bytes [Code char 20] / / armazenar até 20 bytes
boolean connected = false; boolean conectado = false;
void setup() // run once, when the sketch starts void setup () / / executa uma vez, quando o desenho começa
{ (
pinMode(ledPin, OUTPUT); // sets the digital pin as output pinMode (ledPin, OUTPUT); / / configura o pino como saída digital
Serial.begin(9600); Serial.begin (9600);
} )
void loop() // run over and over again void loop () / / executa repetidamente
{ (
checkSerial(); checkSerial ();
} )
// Check Serial port if any bytes received from C++ / / Verificar se a porta serial qualquer bytes recebidos C + +
void checkSerial() { void checkSerial () (
if(Serial.available() > 0) { // if data available from reader if (Serial.available ()> 0) (/ / se os dados disponíveis do leitor
if((val = Serial.read()) == 10){ // check for chr(10) initiation if ((val = Serial.read ()) == 10) (/ / verificação para chr (10) o início
bytesread = 0; bytesRead = 0;
while(bytesread<20){ // read up to 20 bytes while (bytesRead <20) (/ / ler até 20 bytes
if( Serial.available() > 0) { if (Serial.available ()> 0) (
val = Serial.read(); val = Serial.read ();
if(val == 13) { // check for chr(13) termination if (val == 13) (/ / verificação para chr (13) denúncia
break; // stop reading break; / parar de ler
} )
code[bytesread] = val; // add the byte [Code bytesRead] = val; / / adiciona o byte
bytesread++; // ready to read next digit bytesRead + + / / pronto para ler próximo dígito
} )
} )
saySomething(); // Execute received saySomething () / / Execute recebido
bytesread = 0; // reset number of bytes read to zero bytesRead = 0; / / número de bytes lidos repor a zero
delay(50); // wait for a second atraso (50) / / espera por um segundo
} )
} )
} // End of checkSerial ) / / Fim do checkSerial
void saySomething() { void saySomething () (
Serial.print("I received: "); Serial.print ("Eu recebi:");
Serial.println(code); Serial.println (código);
digitalWrite(ledPin, HIGH); // sets the LED on digitalWrite (ledPin, HIGH); / / define o LED
} )
_________________________________________
No c++
Serial::Serial(char *portName)
( {
this-> ligado = false; this->connected = false;
this-> hSerial = CreateFile (portName, this->hSerial = CreateFile(portName,
GENERIC_READ GENERIC_WRITE |, GENERIC_READ | GENERIC_WRITE,
0 0,
NULL, NULL,
OPEN_EXISTING, OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_NORMAL,
NULL); NULL);
:: Memset (& OVR this->, 0, sizeof (this-> OVR)); ::memset(&this->ovr, 0, sizeof(this->ovr));
this-> ovr.Offset = FILE_WRITE_TO_END_OF_FILE; this->ovr.Offset = FILE_WRITE_TO_END_OF_FILE;
this-> ovr.OffsetHigh = -1; this->ovr.OffsetHigh = -1;
if (this-> hSerial == INVALID_HANDLE_VALUE) if(this->hSerial==INVALID_HANDLE_VALUE)
( {
if (GetLastError () == ERROR_FILE_NOT_FOUND) ( if(GetLastError()==ERROR_FILE_NOT_FOUND){
/ / Erro de impressão, se necessário //Print Error if neccessary
printf ("ERRO: Manipular não foi anexado.% Motivo: não é disponível. \ n", portName); printf("ERROR: Handle was not attached. Reason: %s not available.\n", portName);
) }
outro else
( {
printf ("Erro !!!"); printf("ERROR!!!");
) }
) }
outro else
( {
dcbSerialParams DCB = (0); DCB dcbSerialParams = {0};
if (! GetCommState (this-> hSerial & dcbSerialParams)) if (!GetCommState(this->hSerial, &dcbSerialParams))
( {
printf ("não!"); printf("failed!");
) }
CBR_9600 dcbSerialParams.BaudRate =; dcbSerialParams.BaudRate=CBR_9600;
dcbSerialParams.ByteSize = 8; dcbSerialParams.ByteSize=8;
dcbSerialParams.StopBits = ONESTOPBIT; dcbSerialParams.StopBits=ONESTOPBIT;
NOPARITY dcbSerialParams.Parity =; dcbSerialParams.Parity=NOPARITY;
if (! SetCommState (hSerial & dcbSerialParams)) if(!SetCommState(hSerial, &dcbSerialParams))
( {
printf ("\ n \ nALERT: Porta Serial falhou!"); printf("\n\nALERT: Serial port failed!");
) }
outro else
( {
this-> ligado = true; this->connected = true;
) }
) }
) }
Serial: Serial ~ () Serial::~Serial()
( {
if (this-> conectado) if(this->connected)
( {
this-> ligado = false; this->connected = false;
CloseHandle (hSerial this->); CloseHandle(this->hSerial);
) }
) }
bool Serial: ReadData (char * buffer, int nbChar) bool Serial::ReadData(char *buffer, int nbChar)
( {
[SzBuff char 100]; char szBuff[100];
DWORD bytesRead; DWORD bytesRead;
COMSTAT status; COMSTAT status;
erros DWORD; DWORD errors;
ClearCommError ( ClearCommError(
hSerial this-> / / lidar com a comunicação do dispositivo this->hSerial, // handle to communications device
E erros, / / ponteiro para variável para receber os códigos de erro &errors, // pointer to variable to receive error codes
& Status); &status);
if (status.cbInQue> 0) if(status.cbInQue>0)
( {
ReadFile (hSerial este>, szBuff, 1, & bytesRead, NULL); ReadFile(this->hSerial, szBuff, 1, &bytesRead, NULL);
/ / Printf ("% d \ n", (INT) bytesRead); //printf("%d\n", (int)bytesRead);
if (bytesRead! = 0) if(bytesRead != 0)
( {
printf (% c ", szBuff
- ); printf("%c", szBuff[0]);
) }
return true; return true;
) }
return false; return false;
) }
bool Serial: WriteData (char * buffer, int nbChar) bool Serial::WriteData(char *buffer, int nbChar)
( {
tmp DWORD; DWORD tmp;
COMSTAT status; COMSTAT status;
erros DWORD; DWORD errors;
/ / WriteFile hSerial (this->, buffer, nbChar & tmp, NULL); //WriteFile(this->hSerial, buffer, nbChar, &tmp, NULL);
if (! WriteFile (this-> hSerial, (void *) buffer, nbChar, if(!WriteFile(this->hSerial, (void *)buffer, nbChar,
& Tmp, 0)) &tmp, 0))
( {
ClearCommError ( ClearCommError(
hSerial this-> / / lidar com a comunicação do dispositivo this->hSerial, // handle to communications device
E erros, / / ponteiro para variável para receber os códigos de erro &errors, // pointer to variable to receive error codes
& Status); &status);
N "printf ("% d \, (int) erros); printf("%d\n",(int)errors);
return false; return false;
) }
outro else
return true; return true;
) }
bool Serial: IsConnected () bool Serial::IsConnected()
( {
retorno this-> ligado; return this->connected;
) }
Desde já agredeço!