Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I have a motor connected to my computer, which is connected through CAN to the motor. Basically, I have a USB-to-CAN adapter, to which I connect a USB cable from my computer. Then, from the adapter, the motor is connected through CAN.
Now, I wish to send data to the motor- I already know what sequence of bytes I need to send, but I'm not sure what commands to use to "talk" to my motor that is connected through CAN. I have been able to send data by direct USB connection from my computer to motor (using the WriteFile command in C++), but this method does not work for CAN.
Are there any libraries/functions that I can use to talk to my motor via CAN in C++?
Since you cannot connect a motor directly to a CAN bus, there must be some sort of motor controller, drive or I/O controller between the bus. Details of this device are required in order to advise on a more than fundamental level.
CAN itself does not define an application layer protocol, and several application protocols exist for CAN, such as CANopen, DeviceNet and SDS. Your device may use such a protocol or possibly something entirely proprietary. Your starting point should be the documentation for your I/O device.
For testing, most PC CAN adapter manufacturers will provide some sort of debug or development tool that allows you to construct and send individual messages and message sequences at a low-level; such a tool will allow you to verify the operation of the bus and I/O device.
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I'm new to embedded programming and I apologise in advance for any confusion.
I need to handle multiple events from different devices connected to a gpio. These events need to be monitored continually. This means that after one event is generated and handled, the code needs to keep monitoring the device for other events.
I understand the concept of interruptions and polling in Linux (the kernel gets an interruption and dispatch it to the handler which goes on up to the callee of an epoll which is inside an infinite loop while(1)-like).
This is fine for one-time, single-event toy models. In a embedded system with limited resources such as the AT91SAM9x5 that runs at 400mhz and has 128mb of ram what can I do ? I believe that the while(1)-like pattern isn't the best choice. I've heard good things about thread pool solution but at the heart of each thread don't we find a while(1) ?
What are my options to attack this problem ?
Thank you in advance !
For an embedded system, the AT91SAM is actually quite "resource rich" rather than resource limited. The idea is the same as if you writing it using Linux: you set up a pin interrupt, and in your interrupt handler, you do some minimal processing and maybe set up some global data so that your main loop "while (1)" can detect the situation and then process the information in the non-interrupt context. Basically you want the interrupt handler to finish as quickly as possible so that it can handle the next interrupt.
In most systems, interrupts can be pended or nested. With systems that allow nested interrupts, you have to make sure that it does not trash the context of the previous interrupt that is still being executed.
The actual communication scheme between the interrupt handler and the main code depends on your requirement. You can even use an RTOS with support for such requirements.
It depends a lot on what is your application and what are your constrains but here are some of the common methods to monitor gpio pins for event
In many of the newer controllers, all GPIO pins are capable of generating a combined interrupt. You can use this to trigger an ISR call on any change on any of the pins and then inside the ISR detect which specific pin triggered it.
If there is nothing else your controller should be doing, then there is nothing wrong is a while(1) loop continuously monitoring all port pins and triggering relevant actions
If none of the above solutions are acceptable, you can perhaps try to load a small OS like FreeRTOS on your controller and then use different tasks to monitor port pins
A lighter version of the above method is to have a configure a timer interrupt and poll for all the port pins inside it. You can then save the state of pins in global variable and use that in the main loop to take relevant actions.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I am wanting to create a c++ program that will power cables.Like a ethernet cable has several wires in it.How would I choose a wire and send current through it?
If anyone can explain how to send current over specific wires that would be great.I also do not want to use a library.To make it even clearer , I wish to be able to do something like this [Video] https://www.youtube.com/watch?v=H1enhkLZm10 .
I guess this will answer your question: I/O Ports controlled LEDs.
This is a code snippet from the website on how to communicate with a port:
#include <conio.h>
#include <dos.h> // For _out
#define port 0x378 // Port Address
#define data port+0 // Data Port of the parallel cable
void main (void)
{
_out(data, 255); // For all lights on
_out(data, 0); // For all lights off
}
If you don't know how computers communicate with peripherals, and how different ports like USB(Universal Serial Bus), Serial ports, and other ports communicate and work. This guide should help you get started.Control Physical World Through Computer (Step by Step)
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I've read a lot of information about X11 graphic system and found a lot of questions about this issue without answer. So let me ask onу more time.
I need classic implementation of hook mechanism (like SetWindowsHookEx) or any other approach in UNIX-like operation systems with ONLY ONE CONDITION : ability to listen events without blocking original event (like XGrabButton and XUngrabButton do).
P.S. Ben, this is Danila. I need help! ®
I've ended up by grabbing source code from Xnee - it allows record all input events, including keyboard and mouse with non-blocking logic. The only restriction is that I have to ask if there any events in loop with 100ms interval, but it's ok for me - there is no processor loading at all.
Not possible do globally (all events/all windows) unless you read low level communication (using pcap or replacing real xserver with proxy that gives you all the data)
To get notification for particular window you change event mask of that window. Server keeps separate copy of event mask for a window per client, and notifies each client interested in events matching mask. For example, if you add PointerMotion bit to root window event mask from your connection you'll get pointer events when mouse moves over root window (given it's visible)
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
For my thesis I'm given an application written in visual c++ and using MFC that receives gps data (NMEA 183 (RMC)), the data is received from UDP and/or a Serial port (COM port) (they have to work separatly or together). The UDP part of the application is done and its working (written by another student before me), so I have to finish the Serial port part, but here comes my problem, it turns out that MFC does not support COM ports or at least doesn't have a class for serial ports, I found some serial port implementation on the internet: LINK, but I dont know how to integrate it and make it work, it turns out that the UDP part is working like an event triggering mechanism using virtual function CAsyncSocket::OnReceive. I was wondering if its posible to make anything similar to this working with Serial Ports?
Thank you for your help.
Best Regards.
If your program is a GUI then it is a good idea to run the serial port code in a separate worker thread. ReadFile can take a long time to get serial data and this would block the GUI message processing if it was done in the main thread. To provide notification events from the serial thread to the main (GUI) thread you can use PostMessage with a user-defined message. An example of doing this is at
http://vcfaq.mvps.org/mfc/12.htm
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 9 years ago.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
I need to perform continous serial write on the serial port till the application is running . Can anyone suggest what is the appropriate step to continously write data in regular time interval in serial communication using win32 .
I have done port open, write, read and close on button click . It means that if i click open button then it opens the port, write button to write, read button to read and close button to close the port. I have used file operation technique on serial port on win32 platform. The steps can be summarised as
open port (createfile)
check port exist or not
set serial parameters
set timeouts
write data (writefile)
read data (readfile)
close port
I have done this to learn about serial communication . but actually i have to write the data continuously until the application is running and at the same time read the data as it becomes available in the serial port. I have not implemented threading concept in my program . Threading is a new topic for me and if i have to use it to obtain my objective, please suggest an appropriate step. My objectives are
write the data continuously till the application is running.
The continuous data should be written at certain time interval . (is there any timer concept in c++).
Read the data from serial port whenever data is available at the port.
Your help will be really appreciated.
stopSignal=CreateEvent(stuff); //signal this with SetEvent() to stop the serial thread.
..
CreateThread(blah,SerialThreadProc,blah);
..
void* SerialThreadProc(){
open port (createfile);
check port exist or not;
set serial parameters;
set timeouts;
do{
write data (writefile);
read data (readfile);
}while(WAIT_TIMEOUT==WaitForSingleObject(stopSignal,commsInterval));//expect yoda flame
close port
};
If you want to do Windows API serial reads and writes concurrently it is necessary to have a read thread and a write thread. And if you are doing this in a GUI program then these threads should be separate from the main GUI thread.
This MSDN article describes the details and mentions a sample code named MTTTY that combines read, write and GUI. Unfortunately, MTTTY does not seem to be available any more on MSDN. Maybe you can find it if you have access to old MSDN library disks.
http://msdn.microsoft.com/en-us/library/ff802693.aspx