|
jschell wrote: I don't understand that comment.
I can't make it any clearer.
Just say 'NO' to evaluated arguments for diadic functions! Ash
|
|
|
|
|
Essential, if you are compiling a 64 bit application, the compiler would define _WIN64 and since that application would not run on a 32 bit OS, then in that case, it is essentially pointless to actually check the OS. If the OS would have been 32 bits, the application would have fail to load.
Identifier starting with underscore are supposed to be reserved to the compiler so if someone use them anyway the result might be undefined.
Thus only when the application is compiled in 32 bits, it is necessary to do the test.
Philippe Mori
|
|
|
|
|
|
hi
i finally figuered out how to use the binding source commponent of visual c++/cli and i find it really usefull.
i created my own class and assigned it to the bindingsource:
form1BindingSource->Add(gcnew class_constructor_here(textBox1->Text, var1));
now my problem is that the "data" is only stored temporary, so if i close my form program the data is lost.
how can i save the form1BindingSource to a sql database?
i already figuered out how to mke an connection to the database...:
String^ connectString = "Data Source=.\SQLEXPRESS;AttachDbFilename=\"database.mdf\";Integrated Security=True;Connect Timeout=30;User Instance=True";
using (SqlConnection connection = gcnew SqlConnection(connectString))
{
}
now can someone please givve me some hints or tutorials how to save my form1BindingSource to the database?
please... i can't find any usefull stuff in google
thx
sam
|
|
|
|
|
Hi,
I need to program PIC 16F876A to control MCP2515 CAN controller? Anyone got any experience or example to shared? I having trouble in understanding the example code i found.
unsigned char Can_Init_Flags, Can_Send_Flags, Can_Rcv_Flags;
unsigned char Rx_Data_Len;
char RxTx_Data[8];
char Msg_Rcvd;
const long ID_1st = 12111, ID_2nd = 3;
long Rx_ID;
void main() {
PORTC = 0;
TRISC = 0;
Can_Init_Flags = 0;
Can_Send_Flags = 0;
Can_Rcv_Flags = 0;
Can_Send_Flags = _CAN_TX_PRIORITY_0 &
_CAN_TX_XTD_FRAME &
_CAN_TX_NO_RTR_FRAME;
Can_Init_Flags = _CAN_CONFIG_SAMPLE_THRICE &
_CAN_CONFIG_PHSEG2_PRG_ON &
_CAN_CONFIG_XTD_MSG &
_CAN_CONFIG_DBL_BUFFER_ON &
_CAN_CONFIG_VALID_XTD_MSG;
CANInitialize(1,3,3,3,1,Can_Init_Flags);
CANSetOperationMode(_CAN_MODE_CONFIG,0xFF);
CANSetMask(_CAN_MASK_B1,-1,_CAN_CONFIG_XTD_MSG);
CANSetMask(_CAN_MASK_B2,-1,_CAN_CONFIG_XTD_MSG);
CANSetFilter(_CAN_FILTER_B2_F4,ID_2nd,_CAN_CONFIG_XTD_MSG);
CANSetOperationMode(_CAN_MODE_NORMAL,0xFF);
RxTx_Data[0] = 9;
CANWrite(ID_1st, RxTx_Data, 1, Can_Send_Flags);
while(1) {
Msg_Rcvd = CANRead(&Rx_ID , RxTx_Data , &Rx_Data_Len, &Can_Rcv_Flags);
if ((Rx_ID == ID_2nd) && Msg_Rcvd) {
PORTC = RxTx_Data[0];
RxTx_Data[0]++ ;
Delay_ms(10);
CANWrite(ID_1st, RxTx_Data, 1, Can_Send_Flags);
}
}
}
unsigned char Can_Init_Flags, Can_Send_Flags, Can_Rcv_Flags;
unsigned char Rx_Data_Len;
char RxTx_Data[8];
char Msg_Rcvd;
const long ID_1st = 12111, ID_2nd = 3;
long Rx_ID;
void main() {
PORTC = 0;
TRISC = 0;
Can_Init_Flags = 0;
Can_Send_Flags = 0;
Can_Rcv_Flags = 0;
Can_Send_Flags = _CAN_TX_PRIORITY_0 &
_CAN_TX_XTD_FRAME &
_CAN_TX_NO_RTR_FRAME;
Can_Init_Flags = _CAN_CONFIG_SAMPLE_THRICE &
_CAN_CONFIG_PHSEG2_PRG_ON &
_CAN_CONFIG_XTD_MSG &
_CAN_CONFIG_DBL_BUFFER_ON &
_CAN_CONFIG_VALID_XTD_MSG &
_CAN_CONFIG_LINE_FILTER_OFF;
CANInitialize(1,3,3,3,1,Can_Init_Flags);
CANSetOperationMode(_CAN_MODE_CONFIG,0xFF);
CANSetMask(_CAN_MASK_B1,-1,_CAN_CONFIG_XTD_MSG);
CANSetMask(_CAN_MASK_B2,-1,_CAN_CONFIG_XTD_MSG);
CANSetFilter(_CAN_FILTER_B2_F3,ID_1st,_CAN_CONFIG_XTD_MSG);
CANSetOperationMode(_CAN_MODE_NORMAL,0xFF);
while (1) {
Msg_Rcvd = CANRead(&Rx_ID , RxTx_Data , &Rx_Data_Len, &Can_Rcv_Flags);
if ((Rx_ID == ID_1st) && Msg_Rcvd) {
PORTC = RxTx_Data[0];
RxTx_Data[0]++ ;
CANWrite(ID_2nd, RxTx_Data, 1, Can_Send_Flags);
}
}
}
|
|
|
|
|
Hi,
1.
you're asking in the wrong forum: C++/CLI is the .Net version of C++, not the PIC version! I will not proceed here beyond this single reply.
2.
I have done lots of CAN applications, and I have used several PIC models, however I never did real CAN on PIC (I have a CAN-like protocol running on a tiny PIC, all in software though). So all I can offer is a set of advice:
3.
make sure you read all you can get about CAN in general, and thoroughly read your PIC's documentation. Peripherals need a lot of initialization (see the start of your Main functions), and a single error or omission there may cause total failure.
4.
Your test set-up is sending basically the same message back and forth from one PIC to the other, it does not offer any observability: it could be running fine without you noticing anything, or it could fail completely, how can you tell? I suggest you connect a few LEDs (or any other output device) and set their value inside the while loop; displaying a few bits of RxTx_Data[0] should generate an incrementing binary pattern. Observability is key in all debugging, and often is even more important on embedded systems; take care of it from the start, the payback will be immediate.
5.
For any serious application you would need interrupts, and probably also CAN message filtering (assuming multiple PIC nodes and a rather busy CAN bus). Your test has neither. So it may become much more complex.
|
|
|
|
|
Thanks for your advices and I am sorry because I am confused where to post my question since the source code is in .c file type so I am thought i can post it in C++.
It would be great if u can gives me some link to some example of CAN using PIC since I can't really find one that I manage to understood.
|
|
|
|
|
use either the hardware forum or the C/C++ forum. I will probably see it where ever you put it!
search for:
PIC application notes
PIC AN738
TCanDriver
16F876 CAN source code
if you need more help, ask specific questions; however begin with providing detailed context: are you using a kernel/operating system? do you need to interact with existing CAN nodes? if so, what specific CAN protocol do you need? what is the application? what is the bit rate, the bus load to be expected, the rate of *other* interrupts, etc etc.
Embedded systems aren't simple. If this were your first experiment, start with simpler things: a few LEDs (needed anyway for debugging), a serial port. When you feel comfortable, switch to more complex stuff (such as USB, Ethernet, CAN).
End of thread.
|
|
|
|
|
yea, this is the first time I experiment with CAN. I was confuse where to start with. I have already collected and roughly go through the data sheet for each PIC needed. After that, I drawn the circuit diagram and then tried to understand the source code I posted above but its too complicated for a beginner like me.
I really appreciated your prompt reply. I think i should make myself more clear before I ask questions.
Thanks again for your prompt reply. Hope to receive your reply for my future question. 
|
|
|
|
|
Hi Luc Pattyn,
Do you used simulation to run your CAN project? If yes, may I know what is the simulator? I have a proteus 7 software which can do simulation job, but the problem is the software dont have MCP 2551 and MCP 2515 device. I cant find the library.
I have done a simple program but it does not run when i burn into the microcontroller (pic 16f877). There is no compilation error also.
CAN node 1
unsigned char Can_Init_Flags, Can_Send_Flags, Can_Rcv_Flags;
unsigned char Rx_Data_Len;
char RxTx_Data[8];
char Msg_Rcvd;
const long ID_1st = 12111, ID_2nd = 3;
long Rx_ID;
sbit CanSpi_CS at RC0_bit;
sbit CanSpi_CS_Direction at TRISC0_bit;
sbit CanSpi_Rst at RC2_bit;
sbit CanSpi_Rst_Direction at TRISC2_bit;
void main() {
PORTA = 0x00;
TRISA = 0xFF;
PORTD = 0x00;
TRISD = 0x00;
Can_Init_Flags = 0;
Can_Send_Flags = 0;
Can_Rcv_Flags = 0;
Can_Send_Flags = _CANSPI_TX_PRIORITY_0 &
_CANSPI_TX_XTD_FRAME &
_CANSPI_TX_NO_RTR_FRAME;
Can_Init_Flags = _CANSPI_CONFIG_SAMPLE_THRICE &
_CANSPI_CONFIG_PHSEG2_PRG_ON &
_CANSPI_CONFIG_XTD_MSG &
_CANSPI_CONFIG_DBL_BUFFER_ON &
_CANSPI_CONFIG_VALID_XTD_MSG;
SPI1_Init();
CANSPIInitialize(1,3,3,3,1,Can_Init_Flags);
CANSPISetOperationMode(_CANSPI_MODE_CONFIG,0xFF);
CANSPISetMask(_CANSPI_MASK_B1,-1,_CANSPI_CONFIG_XTD_MSG);
CANSPISetMask(_CANSPI_MASK_B2,-1,_CANSPI_CONFIG_XTD_MSG);
CANSPISetFilter(_CANSPI_FILTER_B2_F4,ID_2nd,_CANSPI_CONFIG_XTD_MSG);
CANSPISetOperationMode(_CANSPI_MODE_NORMAL,0xFF);
RxTx_Data[0] = 9;
CANSPIWrite(ID_1st, RxTx_Data, 1, Can_Send_Flags);
}
CAN node2
unsigned char Can_Init_Flags, Can_Send_Flags, Can_Rcv_Flags;
unsigned char Rx_Data_Len;
char RxTx_Data[8];
char Msg_Rcvd;
const long ID_1st = 12111, ID_2nd = 3;
long Rx_ID;
sbit CanSpi_CS at RC0_bit;
sbit CanSpi_CS_Direction at TRISC0_bit;
sbit CanSpi_Rst at RC2_bit;
sbit CanSpi_Rst_Direction at TRISC2_bit;
void main() {
PORTA = 0x00;
TRISA = 0x00;
PORTD = 0x00;
TRISD = 0x00;
Can_Init_Flags = 0;
Can_Send_Flags = 0;
Can_Rcv_Flags = 0;
Can_Send_Flags = _CANSPI_TX_PRIORITY_0 &
_CANSPI_TX_XTD_FRAME &
_CANSPI_TX_NO_RTR_FRAME;
Can_Init_Flags = _CANSPI_CONFIG_SAMPLE_THRICE &
_CANSPI_CONFIG_PHSEG2_PRG_ON &
_CANSPI_CONFIG_XTD_MSG &
_CANSPI_CONFIG_DBL_BUFFER_ON &
_CANSPI_CONFIG_VALID_XTD_MSG &
_CANSPI_CONFIG_LINE_FILTER_OFF;
SPI1_Init();
CANSPIInitialize(1,3,3,3,1,Can_Init_Flags);
CANSPISetOperationMode(_CANSPI_MODE_CONFIG,0xFF);
CANSPISetMask(_CANSPI_MASK_B1,-1,_CANSPI_CONFIG_XTD_MSG);
CANSPISetMask(_CANSPI_MASK_B2,-1,_CANSPI_CONFIG_XTD_MSG);
CANSPISetFilter(_CANSPI_FILTER_B2_F3,ID_1st,_CANSPI_CONFIG_XTD_MSG);
CANSPISetOperationMode(_CANSPI_MODE_NORMAL,0xFF);
Msg_Rcvd = CANSPIRead(&Rx_ID , RxTx_Data , &Rx_Data_Len, &Can_Rcv_Flags);
if ((Rx_ID == ID_1st) && Msg_Rcvd) {
PORTD = 0x01;
}
else
PORTD = 0x08;
}
The result is 0000 1000, which means node 2 does not received any message from node 1.
I hope you can advise me in this problem. Thanks.
|
|
|
|
|
No, we never used simulation for CAN. I am also unfamiliar with CANSPI library, we used our own code, directly accessing the hardware.
Some thoughts:
1.
If the first node sends before the second got through initialization, the message would be lost. Having both nodes powered by the same supply (just a guess), and/or even connected to the same reset line, would still leave a timing uncertainty on which starts up first, and how big the launch time difference would be (tens of msec easily).
2.
is CANSPIRead() a blocking function? and would it work right after initialization?
Suggestion: I would make one node send one message per second, say an incrementing number; then see of the second node gets anything at all.
|
|
|
|
|
Hi,
Hmm, so you are suggesting that I should have several lines of CANSPIWrite()?
There are many things that I still not sure....I just experiment with it.
However, thanks a lot for your prompt reply.
regards,
kent
|
|
|
|
|
Hi Luc Pattyn,
I have one favor to ask. Can you take a look on my system diagram? I want to make sure that my connection is ok. However, I don't know how to upload the image on this forum. I can email my system diagram to you, if you are fine with it.
Thanks.
Regards,
Kent
|
|
|
|
|
You need some Gold or Platinum reputation around here to get upload capabilities.
However you could upload to some public service (such as Flickr), then post the link here.
BTW: You are totally abusing this forum, even more than when you started this thread.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
|
I haven't checked the diagram against the datasheets or application notes from the manufacturer, you should if you haven't already. There aren't many ways to connect things up anyway.
kent5244 wrote: Abusing the forum?
I suggest you read again the very first sentence I've replied in this thread.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
May I know how to convert SAFEARRAY to System::Object,
error C2664: void .....(System::String ^,System::Object ^)' : cannot convert parameter 2 from 'SAFEARRAY *' to 'System::Object ^'
thanks
|
|
|
|
|
|
Hi,
I m new to CLI ,
Can anyone tell me How to use C DLL in C++/CLI???
Thanks,
Sachin
|
|
|
|
|
|
how to convert tchar to lpcwstr
|
|
|
|
|
TCHAR is single unit, LPCWSTR would be set of units.
See this[^]
|
|
|
|
|
Dear Friends
I am facing some problems in deploying my application for lower version of qt.
Basically i want to generate scripts for my application and I have chosen pythonqt for this purpose. Pythonqt has the problem with lower version of Qt (Qt 4.5.2) and also with Higher version of Qt (Qt 4.7). So I needed to get another machine where I have installed Qt-4.6.3 with in-built python version 2.6. I am successfully able to generate my application exe and it is running.
But the requirement is that this exe should run on my original machine so I built the application with the static link of Qt4.6.3-static.
My original machine has python2.3 installed.
But I am not able run on original machine. Its giving 3 library linking problem. as below
libpng14.so.14 => not found
libEGL.so.1 => not found
libpython2.6.so.1.0 => not found
I have libpng12 installed in original system......I am keeping the libong14 from my new machine in a local lib folder and exporting LD_LIBRARY_PATH to/the/local/lib but still its not able to find the libpng14
similarly for libpython2.6 I am keeping the libpython2.6 from new machine into the local lib folder. but its not recognizing.
libEGL i dont even know.
Please give me some suggesstions what can be done.
Thanks sujan
|
|
|
|
|
And what does this have to do with "Managed C++/CLI"?
Just say 'NO' to evaluated arguments for diadic functions! Ash
|
|
|
|
|
using namespace System::Runtime::InteropServices;
public ref class CTest
{
public:
static delegate bool Callback(int i);
}
While compliting I get error.
error C2144: syntax error : 'bool' should be preceded by ';'
I would like to use delegate as a callback function and select one of the serval avaliable function.
Please advice. thanks.
|
|
|
|
|