|
Most Welcome
Yes U Can ...If U Can ,Dream it , U can do it ...ICAN
|
|
|
|
|
This is still wrong! If you compile this code on a system where _WIN64 is defined then the generated code will return TRUE from the Is64BitWindows() function. However if you then run that same code on a 32 bit system it will still return TRUE and your program will most likely fail. You need to understand the difference between compile time and run time tests.
Just say 'NO' to evaluated arguments for diadic functions! Ash
|
|
|
|
|
<blockquote class="FQ"><div class="FQA">Richard MacCutchan wrote:</div>This is still wrong! If you compile this code on a system where _WIN64 is defined then the generated code will return TRUE from the Is64BitWindows() function</blockquote>
The _WIN64 macro is a Microsoft compiler option that indicates that the code is being compiled for 64 bits.
The following link says that is what it is.
http://msdn.microsoft.com/en-us/library/b0084kay.aspx[^]
So excluding someone using that macro incorrectly (if even possible) the compiled code would then be compiled to run on 64 bits.
And a 64 bit application won't run on a 32 bit machine - right?
So what would be the situation where it returns an incorrect result?
|
|
|
|
|
jschell wrote: And a 64 bit application won't run on a 32 bit machine - right?
Correct.
jschell wrote: So what would be the situation where it returns an incorrect result?
I'm not sure that I understand your question fully. However in the case above that I commented on, if the code is compiled on a system with _WIN64 defined, and then run on a 32 bit system, it wil return TRUE from that function thus thinking that it is on a 64-bit system. I have no idea what the outcome would be but I would expect it to fail at some point.
Just say 'NO' to evaluated arguments for diadic functions! Ash
|
|
|
|
|
Richard MacCutchan wrote: However in the case above that I commented on, if the code is compiled on a system with _WIN64 defined, and then run on a 32 bit system, it wil return TRUE from that function thus thinking that it is on a 64-bit system.
The _WIN64 is a VS compiler macro that is only defined when VS is set up to compile to a 64 bit binary.
A 64 bit binary will not run on a 32 bit platform.
If both of those are true then the result of the method is irrelevant.
Do you believe that one of those is false?
If so why?
|
|
|
|
|
jschell wrote: If both of those are true then the result of the method is irrelevant.
Quite possibly, but the thinking behind the code is still flawed.
Just say 'NO' to evaluated arguments for diadic functions! Ash
|
|
|
|
|
I have been reflecting on this point and your answer. I think the reason for my comments was based on a situation I had when working on a multi-platform system some years ago. We had a similar situation where our manager insisted the code by written with #ifdef 's, even though we had explained to him that it needed to be execution time tests. After releasing the code we were proved right and the manager's career did not last much longer. As you pointed out, this situation is somewhat different.
Just say 'NO' to evaluated arguments for diadic functions! Ash
|
|
|
|
|
Richard MacCutchan wrote: We had a similar situation where our manager insisted the code by written with #ifdef's, even though we had explained to him that it needed to be execution time tests.
I don't understand that comment.
If I am targetting a 32 bit platform and a 64 bit platform then I would really expect that I must run two complete set of tests, one on the 32 and one the 64 bit.
And if the functionality was different at a minimum I would loudly and repeatedly state that I would expect it to fail if it wasn't tested on a specific target. I would be nervous even if it was exactly the same. Especially with C++ (or C.)
|
|
|
|
|
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
|
|
|
|
|