OPC on Mac OS, possible?

Discussion in 'Mac Programming' started by 99bobster99, Aug 2, 2011.

  1. 99bobster99 macrumors newbie

    Aug 2, 2011

    I am new to the Mac environment and have been tasked with programming some data exchange between a vision camera and a Mac PC. The camera has a built-in OPC data server, which I was hoping to use to broadcast a value read from a barcode over to the Mac PC, the Mac PC would then play a referenced iTunes song from this barcode value. Does anyone have any suggestions on the best way to implement this task?
  2. GorillaPaws macrumors 6502a


    Oct 26, 2003
    Richmond, VA
    Will this have a GUI? Or run in the background as a windowless app?

    Can you tell us more about the Camera? by "Vision Camera" do you mean a video camera? a particular model of a still photo digital camera? something else?
  3. 99bobster99 thread starter macrumors newbie

    Aug 2, 2011
    The preliminary plan (depending on complexity) would be;

    -> a vision camera (Festo SBOI-Q OCR capable camera, link; http://www.festo.com/cms/en-us_us/12829.htm this camera has Ethernet capabilities as well as a built-in OPC server.

    this camera reads the barcode label of a card, placed by the guest user within the field of view.

    -> the camera would read the value, as a "1", "2", "3", etc. The camera would "somehow" send this value to the Mac PC.

    -> the Mac PC would read this value (from a playlist directory maybe?) and play an assigned song for each of the values read.

  4. chown33 macrumors 604

    Aug 9, 2009
    Sailing beyond the sunset
    The underlined part seems backwards to me. An OPC server should be like any other server: it responds to requests from clients. So to get the data, the Mac or PC needs to act in the role of an OPC client and request something from the server. Exactly how it should do that, I don't know, but I'm pretty sure it's going to involve some OPC client software of some kind.

    A few googles of OPC client shows a number of hits. OPC client C shows additional hits, for client software written in C or C++. You'll probably have to port it, unless it happens to be Posix-compliant C code.

    Once you have the OCR data (or whatever data the OPC server delivers), you may have to do additional translation, decoding, encoding, etc. You then send the translated action as an AppleEvent to iTunes. Or you could maybe execute the 'afplay' command (type 'afplay -h' in a Terminal window).
  5. GorillaPaws macrumors 6502a


    Oct 26, 2003
    Richmond, VA
    If there aren't existing drivers for your device you'll need to use Apple's I/O Kit Framework. Just to be clear, does the camera output images? or does it process the image and return the value of the barcode? In other words, are you planning on writing your own custom barcode image to value translator?

    You interface with iTunes via Applescript, so you're going to need to learn Objective-C to interface with the the Scripting Bridge Framework to pass in actions to iTunes.

    This sounds like a major undertaking, especially if you're going to write a barcode image translator. I'm not an expert in any of these technologies, so there may be better ways to do this than I'm aware of.

    Edit: Chown33 beat me to it.
  6. 99bobster99 thread starter macrumors newbie

    Aug 2, 2011
    Yes, chown33, there looks to be some middleware software which Festo uses to communicate with the vision camera. It is called EasyServer. This software runs on Windows and serves the camera data to the OPC Client. Is there a way to run this Windows EasyServer software on the Mac and then serve the data values read to the iTunes app, automatically, in the background?

    Would it be possible to program a utility to create the name of a song (text file) in reference to the values read from the camera ("1", "2", "3" ..) and drop this name into an empty directory. If iTunes could monitor this directory automatically, and if a name is present, it would play this song from a playlist? Once it was done playing the song, the text file could be deleted?

    As gorillapaws mentioned, I don't want to get into any NASA programming here, I am looking for a simple approach, to what seems like should be doable?

    GorillaPaws, the camera does return the actual value read from the OCR. I have that working properly. The trick now is how to get this information over to iTunes?
  7. 99bobster99 thread starter macrumors newbie

    Aug 2, 2011
    Would it be possible to run an OPC communication software developed for Windows on the Mac OS? Are the OPC functions not specific to the Windows platform? If this is possible what would I need to run on the Mac to accomplish this task?
  8. chown33, Aug 2, 2011
    Last edited: Aug 2, 2011

    chown33 macrumors 604

    Aug 9, 2009
    Sailing beyond the sunset
    If you mean "an executable compiled for Windows", the answer is likely "No". You'd have to run an actual instance of Windows, but you could do it under a virtualization scheme like VMWare, Parallels, etc. Google search terms: mac virtual windows.

    The Mac could simultaneously be running virtual Windows, along with other Mac-based programs. It might take a lot of RAM and not too speedy, but it might be simpler than setting up an actual physical Windows box.

    If you mean "link a program whose source I have, without porting it", it's possible that WINE (google: winelib) might work. Hard to say without knowing anything else about the program. My guess: WINE won't make it work.

    From what I've read with a little googling, OPC defines a network protocol. It's not specific to Windows or any other platform. Of course, that doesn't necessarily mean it would be easy to find OPC software that runs on platforms other than Windows. And it doesn't mean that my cursory reading of what OPC is is completely accurate.

    It's difficult to gauge how to answer some of your questions, because you haven't told us what programming experience you have, what languages, what client/server experience, etc.

    You might also outline how you got the camera "working properly", and exactly what that means. Did you get an existing Windows OPC client talking to it? Compiled and ran an OPC client in C?

    Something just occurred to me: Why does this have to run on a Mac?

    iTunes on Windows is a scriptable COM application. Google: itunes windows scripting. Example here and here.

    Presumably the OPC software already runs on Windows.

    So just tie it together using something that already runs on Windows, like maybe C# or something else.

    Unless there's some compelling reason to inject a Mac into this, I don't see what would be gained by doing so.
  9. 99bobster99 thread starter macrumors newbie

    Aug 2, 2011
    Thank you for your feedback chown33!

    I have experience in VB and C++, in the Windows environment, I know nothing about the Mac world. Unfortunately, I need to get this setup functional under the Mac environment, the Windows environment is not an option for me. A good suggestion though, since I couldn't find much on Google regarding OPC and the Mac. My hope was to be able to run this OPC server software, meant for Windows, on the Mac. I really like gorillapaws' idea about using the Applescript to activate iTunes to play the required song. I am unsure about the amount of middleware I need to create in the Mac environment in order to accomplish this though??
  10. chown33 macrumors 604

    Aug 9, 2009
    Sailing beyond the sunset
    Like anything else: Break It Down.

    I see nothing mind-bendingly difficult here. It's mostly just breaking it down into sub-tasks, and doing basic feasibility research. I don't see any magical instant solution, either, so you should decide first how much time and effort you're willing to put into doing the research, plus any languages or tools you'll have to learn.

    Languages you know: VB and C++. There's no VB on Macs. That leaves C++, which is supported. So that tells you what to search for in OPC client software source code. You may still run into Windows-isms, or platform-specific things, that interfere with porting the code to Mac OS X.

    If you can't find OPC client source code, maybe there's a ready-made OPC client library, or an OPC client command-line tool. Befriend google.

    It's relatively easy to run an AppleScript from the command-line, or a command-line from AppleScript. The former: the 'osascript' command (google it). The latter: the 'do shell script' command in AppleScript (google it).

    As to running Windows under virtualization: see products already listed. Do some research. Figure out your budget (time and money).
  11. 99bobster99 thread starter macrumors newbie

    Aug 2, 2011
    Thank you for the insight chown33, I have done quite a bit of searching on google and have been discovering a lot of Mac utilities (Wine, OpenOPC, SoftWindows). As you have noticed, the biggest piece of the puzzle for me is the Mac environment, I can program this up in 2 hours using Windows, but it is not as easy in the Mac world (due to my lack of knowledge I'm sure).

    If there were an "off the shelf" OPC software I could use similar to Festo's OPC EasyServer, that would be great. Seeing as they are using a unique comm "EasyIP", I think this will be hard to achieve. This would only leave trying to run Festo's EasyServer utility in a Windows environment within the Mac OS. Since I don't have a Mac to test yet (will have in a week), this is all theory at the moment. As you mentioned, I foresee lots of Window-isms happening trying to run this OPC server utility within Mac land. Are any of the "Windows Emulator" packages better than another? Worse comes to worse I could run the OPC EasyServer software in the background and then use the apple scripting to initiate commands to iTunes.
  12. Hansr macrumors 6502a

    Apr 1, 2007
    I didn't read the whole thread so I may have missed an explanation for this but if this is going to be barcode based why not just use a barcode reader where there are multiple options already for Mac that wouldn't require a server client relationship, just a simple listening processor for the input on the receiving machine?
  13. helioz2000 macrumors newbie

    Aug 7, 2011
    I have looked into this very same issue of linking a mac via OPC to industrial equipment (PLC in my case) .
    I didn't find a suitable solution as OPC is embedded deep within the Win OS and is very much a Microsoft thing with all it failings.

    I ended up using Modbus TCP, there are a number of free libraries for mac out there. I can email you some code if you wish.

    If you keep going down the OPC path, look for FreeBSD or BSD code related to OPC, it will run on OS X which is FreeBSD based.

    If you need to run WinDoze in OS X I would recommend VirtualBox. It's free, easy to use, and works better than many of the paid emulators. My apps run faster under VirtualBox than they do on my Windows box.

    Please let us know how you go.
  14. subsonix macrumors 68040

    Feb 2, 2008
    It seems like you can connect to the device over ethernet, then sending control commands to it. From the Festo site:

    "SBOx-Q communicates with numerous Festo and external controllers - using standardized software interfaces via Ethernet (TCP-IP, Easy IP, Telnet, Modbus TCP) and CAN. New: Ethernet/IP"

    I guess you would have to contact Festo or look for documentation on what commands to send it once you have connected to it.
  15. 99bobster99 thread starter macrumors newbie

    Aug 2, 2011
    Nice find subsonix! It still sounds like I'd need some sort of middleware to send/receive the ethernet commands from the camera, then create and execute the apple script? Could this be done via some sort of batch file? I am looking for an easy solution to take a number from 1 to 10 coming from the camera (song selection) and based on this number have iTunes play the corresponding song referenced to each of these 10 values. Any ideas?

Share This Page