[ASK] About Cocoa Programming with FTDI D2XX driver
Hi all. I'm still a newbie in Cocoa programming. I'm doing a project that using a FTDI usb driver (d2xx) to access an evaluation board that has a FT2232 chip on it. I already search the web for a couple days, an haven't been able to find a single clue. Has anyone use the driver to access any board? If there are, would you mind to give me some clue about the connection.
The current condition is, i installed the driver, and i could see the usb is connected to my macbook. (i check it on the /dev). Then i use the library in a simple app (just a window and few button) to try to open, access the usb and communicate to the board. Then i used a c function (from my previous driver program in windows) and import it as a resource. I used the c function to write a register on the board. You could say that i'm porting the c function to cocoa environment. I managed to do that, but after a certain amout of time, sometimes, an error came, and forced the app to quit. The error sounds like this:
Program received signal "EXEC_BAD_ACCESS".
warning : Unable to restore previously selected frame.
warning : Unable to restore previously selected frame.
warning : check_safe_call: could not restore current frame.
...and so on.
And sometimes the error sounded like : In '__CFRunLoopLock' , file /SourceCache/CF/CF-550.19/RunLoop.subproj/CFRunLoop.c, line 438, during lock, spin lock 0x7fff838aa02e has value 0x24546f0f, which is neither locked or unlocked. The memory has been smashed.
Do i have to do a certain procedure when accessing usb, like create an cfrunloop or nsrunloop? or should i wait a certain period when accessing usb? i already search for that, but i still can't find a clue about it. or is it simply impossible to port a c function like that?
Sorry for my bad English, and looking forward to any clue.
AW
Hey D
I think you're in a little trouble here. The RunLoop stuff is to do with the event loop for the user interface and that business of 'unable to restore previously selected frame' sounds to me as though you might have run out of run-time stack and that would be because maybe:1) You've allocated too much stack stuff char buffer[100*1000*1000] and/OR
2) Recursive overflow
3) You've corrupted your stack (buffer overflow, invalid memory access - the usual horrors of C)
Is it possible to get your driver to work from the command-line in 'C'. Then worry about Cocoa later.
Robin
Hey Robin,
Thanks for your reply. So i assume your suggestion is to try the driver first by creating a simple program that uses command line in C, is that correct? I'll try that asap.
About the stack, i read somewhere in the web that if 'unable to restore previously selected frame' error appears, that mean i have to add more stack buffer.It seems that i misunderstand that. i'll try to reduce the stack too. What do you mean about recursive overflow? Sorry for asking to much question.
Thank you so much. will be posting the result as soon as i can.
Regards,
Adi
Hi Adi
Yes, write a little command-line program. You're dealing with 2 new strange worlds: the Mac and Cocoa. If it's possible, try to get your driver to work on the Mac, then worry about Cocoa.
A recursion is a program that calls itself. (well actually a recursion is a self-reference with a terminal condition). If you do (in C)

If I make the size of buffer[20000] bigger, it'll explode in fewer recursions (smaller, more recursions). However it will explode.
When you have too much data for the run-time stack, that's an 'overflow'. If the condition is caused by recursion that's a 'recursive overflow'.
There are command-line options for the linker to tell about your request for stack space. However I can hardly ever recall having to change the default. Trouble with the stack is usually one of the things I mentioned earlier. You are correct however is saying that allocating more space on the stack may be all you need to do. However I'll be surprised.
It looks to me that you have corrupted your stack (that's what the frame stuff is about). If the stack's been corrupted (by a buffer overflow or something), your process get terminated.
Hi Didotz,
When I was using the FTDI drivers a few years ago in windoz I had a similar problem with frame error. It turned out that it was related to the FTDI usb chip? I can't remember if or how I fixed it as I was just playing around with it at the time. Maybe check the state of the FTDI chip?
Cheers
Adam