Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

[solved] Sending different triggers via serial port

edited July 2013 in OpenSesame

Dear community,

thanks again for helping me with my other problem. I now want to send two different triggers via serial port to our EEG. I therefore prepared two inline scripts:

exp.serial_port.write(chr(1))

and

exp.serial_port.write(chr(2))

This should send two different triggers to the EEG, right? Unfortunately neither BioTrace (our recording software) nor Brain Vision Analyzer (for analysis) show two different triggers. I'm not sure whether the python code is wrong or our software is unable to recognize different triggers.

Best wishes,

Daniel

Comments

  • edited 9:08PM

    Hi Daniel,

    This should send two different triggers to the EEG, right?

    Indeed it should.

    I'm not sure whether the python code is wrong or our software is unable to recognize different triggers.

    The Python code is correct, but there could be a lot of different reasons for why you don't see the trigger in the BioTrace. The most obvious one is that the code, although valid, is not actually executed. You can find this out by printing something to the debug window after sending the trigger:

    exp.serial_port.write(chr(2))
    print 'I just sent trigger 2! (or did I ... ?)'
    

    Another possibility is that you are sending triggers to the wrong port. When setting up a connection, you have to specify whether you want to use COM1, COM2, etc. If you choose the incorrect port, your triggers will go nowhere.

    Could it be either of those two things?

    Cheers,
    Sebastiaan

  • edited June 2013

    A rather nasty error we've encountered in our labs, is that sometimes triggers are sent, but not recognized by the system you're sending them to. In our case, we tried sending parallel port triggers to a BioPac system. The system did not seem to respond. After measuring the parallel port voltage directly from the pins, we discovered that a signal was being transferred. Also, the BioPac did respond to the same type of triggers in a different setup. We concluded that the parallel port output of our computer was simply too weak to be recognized as a trigger by the BioPac (< 3.5 V).

    I have to admit that serial ports are a somewhat different system, but it still might be a good idea to manually check (using a voltmeter on the pins of your cable) whether your computer might actually be giving an output, when you can't find any problems in your code.

  • edited 9:08PM

    Thanks for your replies! I forgot to mention (shame on me) that I can see the triggers in both programes. So sorry for sending you into the wrong direction :-(

    The actual problem is that the programes can't differentiate between trigger 1 and trigger 2. According to sebastiaan my code is right, so probably BioTrace is just unable to recognize two different triggers.

    Instead of

    Trigger 1
    

    or

    Trigger 2
    

    it shows

    Trigger
    

    I'll have a chat about this with the BioTrace developers. Maybe they have a solution.

  • edited 9:08PM

    Today I managed to send several different triggers to our EEG by using the port output test of Presentation (trigger 2, trigger 3...):

    image

    however, with OpenSesame different triggers aren't recognized (trigger 0, trigger 0...):

    image

    Do you guys have any idea how I can fix it?

    Best wishes,
    Daniel

  • edited June 2013

    Hi Daniel,

    The following code ...

    # Open connection
    import serial
    exp.serial_port = serial.Serial('COM1') # Can also be COM2, COM3, etc.
    # Send byte
    exp.serial_port.write(chr(1)) # Send the byte 1 as a character
    # Close connection
    exp.serial_port.close()
    

    ... will send byte 1 via the serial port to COM1. pyserial expects a character, which is why you need to send chr(1) rather than simply 1. But that's not important: Characters and bytes are equivalent, just different interpretations of the same 8 bits.

    Since this code snippet is pretty straight-forward and serial port communication has been extensively tested and used, I think the source of the problem might be that the BioTrace simply expects something different than what you are sending.

    For example, the constructor (the serial.Serial() part) takes many optional parameters, such as the baudrate, etc. If the BioTrace expects a specific configuration, this is a property of the system that you simply have to know.

    Similarly, the BioTrace might expect a specific type of data, and not just a byte-value. Again, this is a property of the system that you have to know.

    I would first check the Presentation settings to see whether and how they have specified properties of the connection: What is the baudrate, etc.? If you can't figure it out, I would ask the BioTrace developers for an example Python snippet.

    Cheers,
    Sebastiaan

    PS. A quick test would be to send all possible values and see how the BioTrace responds:

    for i in range(256):
        exp.serial_port.write(chr(i))
        self.sleep(200)
    
  • edited 9:08PM

    Hi!

    Thanks again for your reply. The required values are (according to the Nexus Trigger Interface user manual):

    Data bits: 8
    Start bits: 1
    Stop bits: 1
    Baudrate: 115200
    Parity: none
    Flow control: none
    

    Where do I have to insert these values? Sorry to ask but I'm really not a professional python programmer ;-)

    Thanks for your help!

    Daniel

  • edited 9:08PM

    You can pass these as keywords to the constructor, like so:

    import serial
    serial_port = serial.Serial('COM1', baudrate=115200, bytesize=serial.EIGHTBITS)
    

    baudrate is a keyword, and you can find a full list of keywords here:

    Some things may not be entirely clear, so you may have to try out a few settings. Also, it's probably a good idea to also familiarize yourself a bit with Python:

    Cheers!

  • edited 9:08PM

    Hi Sebastiaan,

    I added a small modification and it works just perfect now:

    import serial
    exp.serial_port = serial.Serial('COM1', baudrate=115200, bytesize=serial.EIGHTBITS)
    

    Again: many thanks to you!

  • edited 9:08PM

    Great! Glad to hear you got it resolved.

Sign In or Register to comment.

agen judi bola , sportbook, casino, togel, number game, singapore, tangkas, basket, slot, poker, dominoqq, agen bola. Semua permainan bisa dimainkan hanya dengan 1 ID. minimal deposit 50.000 ,- bonus cashback hingga 10% , diskon togel hingga 66% bisa bermain di android dan IOS kapanpun dan dimana pun. poker , bandarq , aduq, domino qq , dominobet. Semua permainan bisa dimainkan hanya dengan 1 ID. minimal deposit 10.000 ,- bonus turnover 0.5% dan bonus referral 20%. Bonus - bonus yang dihadirkan bisa terbilang cukup tinggi dan memuaskan, anda hanya perlu memasang pada situs yang memberikan bursa pasaran terbaik yaitu http://45.77.173.118/ Bola168. Situs penyedia segala jenis permainan poker online kini semakin banyak ditemukan di Internet, salah satunya TahunQQ merupakan situs Agen Judi Domino66 Dan BandarQ Terpercaya yang mampu memberikan banyak provit bagi bettornya. Permainan Yang Di Sediakan Dewi365 Juga sangat banyak Dan menarik dan Peluang untuk memenangkan Taruhan Judi online ini juga sangat mudah . Mainkan Segera Taruhan Sportbook anda bersama Agen Judi Bola Bersama Dewi365 Kemenangan Anda Berapa pun akan Terbayarkan. Tersedia 9 macam permainan seru yang bisa kamu mainkan hanya di dalam 1 ID saja. Permainan seru yang tersedia seperti Poker, Domino QQ Dan juga BandarQ Online. Semuanya tersedia lengkap hanya di ABGQQ. Situs ABGQQ sangat mudah dimenangkan, kamu juga akan mendapatkan mega bonus dan setiap pemain berhak mendapatkan cashback mingguan. ABGQQ juga telah diakui sebagai Bandar Domino Online yang menjamin sistem FAIR PLAY disetiap permainan yang bisa dimainkan dengan deposit minimal hanya Rp.25.000. DEWI365 adalah Bandar Judi Bola Terpercaya & resmi dan terpercaya di indonesia. Situs judi bola ini menyediakan fasilitas bagi anda untuk dapat bermain memainkan permainan judi bola. Didalam situs ini memiliki berbagai permainan taruhan bola terlengkap seperti Sbobet, yang membuat DEWI365 menjadi situs judi bola terbaik dan terpercaya di Indonesia. Tentunya sebagai situs yang bertugas sebagai Bandar Poker Online pastinya akan berusaha untuk menjaga semua informasi dan keamanan yang terdapat di POKERQQ13. Kotakqq adalah situs Judi Poker Online Terpercayayang menyediakan 9 jenis permainan sakong online, dominoqq, domino99, bandarq, bandar ceme, aduq, poker online, bandar poker, balak66, perang baccarat, dan capsa susun. Dengan minimal deposit withdraw 15.000 Anda sudah bisa memainkan semua permaina pkv games di situs kami. Jackpot besar,Win rate tinggi, Fair play, PKV Games