|
Hi everybody, I want to interface a win32 console application with arduino uno via serial port. Can someone help me ?
Thanks a lot.
|
|
|
|
|
nonness wrote: Can someone help me ? With which part specifically?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
I want to send characters from my c++ code to my arduino through the serial port. In fact, i found a tutorial but it is a CLR console application i added some modifications on my win32 application's properties and when i run it there are 0 errors but the program doesn't work :/
|
|
|
|
|
Did you Google[^] for?
Veni, vidi, vici.
|
|
|
|
|
indeed, but i didn't find a suitable result
|
|
|
|
|
What's exactly the problem? Are you able to write a simple application using the serial port on Windows side? On Arduino one?
Veni, vidi, vici.
|
|
|
|
|
I have a code which turns an arduino's pin on and off. This the code:
C++ script:
#include "stdafx.h"
using namespace System;
using namespace System::IO::Ports;
int main(array<System::String ^> ^args)
{
String^ answer;
String^ portName;
int baudRate=9600;
Console::WriteLine("Type in a port name and hit ENTER");
portName=Console::ReadLine();
SerialPort^ arduino;
arduino = gcnew SerialPort(portName, baudRate);
try
{
arduino->Open();
do
{
Console::WriteLine("Type \"on\" to turn the light on or \"off\" to turn it off");
answer=Console::ReadLine();
if(String::Compare(answer,"on")==0)
arduino->WriteLine("1"); else if(String::Compare(answer,"off")==0)
arduino->WriteLine("0"); else
Console::WriteLine(answer+" was not an option");
Console::WriteLine("Try again? yes/no");
answer=Console::ReadLine();
Console::Clear();
}while(String::Compare(answer,"yes")==0);
arduino->Close();
}
catch (IO::IOException^ e )
{
Console::WriteLine(e->GetType()->Name+": Port is not ready");
}
catch (ArgumentException^ e)
{
Console::WriteLine(e->GetType()->Name+": incorrect port name syntax, must start with COM/com");
}
Console::Write("Press enter to close the program");
Console::Read();
return 0;
}
Arduino sketch:
int ledPin = 13;
int state=0;
void setup() {
pinMode(ledPin, OUTPUT); Serial.begin(9600); }
void loop() {
if (Serial.available() > 0)
{
state = Serial.read();
switch(state) {
case '1': digitalWrite(ledPin,HIGH);
break;
case '0': digitalWrite(ledPin,LOW);
break;
default:
break;
}
}
}
Now when i modify the code : when i send a word to the arduino it must return the ascii code of the first letter and the words are : Left Right Forward Back. So, i wrote:
#include "stdafx.h"
using namespace System;
using namespace System::IO::Ports;
int main()
{
String^ answer;
String^ portName;
int baudRate=9600;
Console::WriteLine("Type in a port name and hit ENTER");
portName=Console::ReadLine();
SerialPort^ arduino;
arduino = gcnew SerialPort(portName, baudRate);
try
{
arduino->Open();
do
{
Console::WriteLine("Type \"on\" to turn the light on or \"off\" to turn it off");
answer=Console::ReadLine();
if (((350<=x)&&(x<=550))&&((200<=y)&&(y<=300)) )
{
cout << "Left" ;
arduino->WriteLine("76");
cout << "\n" ;
}
if (((100<=x)&&(x<=250))&&((200<=y)&&(y<=300))){
cout << "Right" ;
arduino->WriteLine("82");
cout << "\n" ;
}if (((300<=x)&&(x<=350))&&((300<=y)&&(y<=400))){
cout << "Back";
arduino->WriteLine("66");
cout << "\n" ;
}
if (((300<=x)&&(x<=350))&&((80<=y)&&(y<=200))){
cout << "Froward" ;
arduino->WriteLine("70");
cout << "\n" ;
}
Console::WriteLine("Try again? yes/no");
answer=Console::ReadLine();
Console::Clear();
}while(String::Compare(answer,"yes")==0);
arduino->Close();
}
catch (IO::IOException^ e )
{
Console::WriteLine(e->GetType()->Name+": Port is not ready");
}
catch (ArgumentException^ e)
{
Console::WriteLine(e->GetType()->Name+": incorrect port name syntax, must start with COM/com");
}
Console::Write("Press enter to close the program");
Console::Read();
}
|
|
|
|
|
While it may not be related to the problem you are having, you might want to consider the Managed C++ forum.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
|
Hi, I have implement a D-Flipflop in C++, I.e. 'D' as a input and 'Q' as a output with 'clk' as a conrol input.
When clk = '1' and D = '1/0' then Q = D;
How to realize clock in C++. It should be of 50% duty cycle using the system frequency. is there any function to use the system clock in program.
|
|
|
|
|
|
I don't need a timing info from the system. It should provide the the system clock as a input to my program.
How to clock in C++/C for the function of digital blocks.
|
|
|
|
|
I don't think that you can get the system clock directly, you need to use one of the time functions provided by the OS.
Manoj7390 wrote: How to clock in C++/C for the function of digital blocks. I'm not sure what you mean by this question.
Use the best guess
|
|
|
|
|
Do you mean simulate the flip flop? That is provide the clock (and other signals) by means of an array?
Veni, vidi, vici.
|
|
|
|
|
What i need is, i need to realize D-Flipflop(Digital block), which transfer the input to output when the clock is high.
Clock should be of 50% duty cycle, means equal amounts of ON and OF periods. How can i do this in C/C++.
|
|
|
|
|
Hi,
I am playing a video file and along with that a Progress bar starts, which indicates the progress of the video file. Now I want to know when the video file has finished playing so that I can reset the position of the Progress bar to 0.
Anybody have any idea regarding this. Any help will be appreciated.
It will be helpful if you can provide some sample code for the same.
Regards,
Mbatra
|
|
|
|
|
Did you notice the EventReceiver() method in the sample project I sent you? It's handling the EC_COMPLETE message.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
Hi David,
Thanks for the info....I didn't notice that.
Now I have one doubt..I am able to figure out when the video play has finished. But at the completion of the video file, I am going to stop the time and reset the progress bar position to 0. Neither the timer is stopped nor the progress bar. Timer keeps on running and progress bar also keeps on stepping up.
Can u please help me how to stop the timer and progress bar.
Regards,
Mbatra
|
|
|
|
|
If you are using pretty much the same code as in the sample, it looks like you can simply add KillTimer(hOwner, MY_TIMEREVENT); to the DoStop() function.
Soren Madsen
"When you don't know what you're doing it's best to do it quickly" - Jase #DuckDynasty
|
|
|
|
|
Hi,
I am using DirectShow to Capture / Play / Stop a video. After capturing a video, when user clicks on the play video button, Video plays fine... But I want to display the progress bar along with the video which will show the user how much video portion is left to play. I also want to display the time along with progress bar, which will take the total duration of the video and will show the user how much time is left.
Anybody have any idea or suggestion for the above mentioned.
It will be very helpful if you can provide me the sample code for the same scenario.
Regards,
Mbatra
|
|
|
|
|
mbatra31 wrote: It will be very helpful if you can provide me the sample code for the same scenario. See here.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
Yes, our code is playing the video.
Regards,
Mbatra
|
|
|
|
|
Hi all. I know almost nothing about client-server programming and I wish you could tell me how to make these two programs work together. I tried running both in terminal with my IP address without success. Thanks :
client
#include <sys/socket.h>
#include <stdio.h>
#include <strings.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <stdlib.h>
#define MAXLINE 100
#define SA struct sockaddr
int main(int argc, char **argv)
{
int sockfd, n;
char recvline[MAXLINE + 1];
struct sockaddr_in servaddr;
if (argc != 2)
fprintf(stderr, "usage: a.out <IPaddress>");
if ( (sockfd = socket(PF_INET, SOCK_STREAM, 0)) < 0)
fprintf(stderr, "socket error\n");
bzero(&servaddr, sizeof(servaddr));
servaddr.sin_family = AF_INET;
servaddr.sin_port = htons(13);
if (inet_pton(AF_INET, argv[1], &servaddr.sin_addr) <= 0)
fprintf(stderr, "inet_pton error for %s", argv[1]);
if (connect(sockfd, (SA *) &servaddr, sizeof(servaddr)) < 0)
fprintf(stderr, "connect error\n");
while ( (n = read(sockfd, recvline, MAXLINE)) > 0) {
recvline[n] = 0;
if (fputs(recvline, stdout) == EOF)
fprintf(stderr, "fputs error\n");
}
if (n < 0)
fprintf(stderr, "read error\n");
exit(0);
}
server
#include <sys/socket.h>
#include <stdio.h>
#include <strings.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <stdlib.h>
#include <time.h>
#include <errno.h>
#include <string.h>
#define LISTENQ 1024
#define MAXLINE 4096
#define SA struct sockaddr
void Close(int fd)
{
if(close(fd) == -1)
fprintf(stderr, "Can't close connection\n");
}
void Write(int fd, void *ptr, size_t nbytes)
{
if (write(fd, ptr, nbytes) != nbytes)
fprintf(stderr, "Write error\n");
}
int Accept(int fd, struct sockaddr *sa, socklen_t *salenptr)
{
int n;
again:
if ((n = accept(fd, sa, salenptr)) < 0) {
#ifdef EPROTO
if (errno == EPROTO || errno == ECONNABORTED)
#else
if (errno == ECONNABORTED)
#endif
goto again;
else
fprintf(stderr, "accept error\n");
}
return(n);
}
int main(int argc, char **argv)
{
int listenfd, connfd;
struct sockaddr_in servaddr;
char buff[MAXLINE];
time_t ticks;
if((listenfd = socket(AF_INET, SOCK_STREAM, 0)) < 0)
fprintf(stderr, "Socket error\n");
bzero(&servaddr, sizeof(servaddr));
servaddr.sin_family = AF_INET;
servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
servaddr.sin_port = htons(13);
if(bind(listenfd, (SA *) &servaddr, sizeof(servaddr)) < 0)
fprintf(stderr, "Bind error\n");
if(listen(listenfd, LISTENQ) < 0)
fprintf(stderr, "Can't listen\n");
for ( ; ; ) {
connfd = Accept(listenfd, (SA *) NULL, NULL);
ticks = time(NULL);
snprintf(buff, sizeof(buff), "%.24s\r\n", ctime(&ticks));
Write(connfd, buff, strlen(buff));
Close(connfd);
}
}
|
|
|
|
|
Using your own IP address with that client is unlikely to work since you probably do not have a daytime listener on port 13. As to your server code, you need to explain where it fails and what errors you see.
Use the best guess
|
|
|
|
|
Hi. I'm getting bind error for the server's code.
|
|
|
|
|