Normally I use SerialPort on a server which has a virtual COM port set up to communicate over the LAN with another computer's point of sale display pole. This is set up as COM3 on the server. Everything works as expected...in production mode only. Having scoured the web for the error that was popping up, I came across a solution where I have to set config.cache_classes = true in development mode. Here's a sample of the code I'm using; keep in mind that regardless of whether or not I have a begin/rescue block, WEBrick still servers a 500 server error. I have to exit the controller method prematurely and return head :no_content before anything happens with SerialPort if I want to avoid this problem in development mode:
POST method - Ajax request from browser app has header X-Message which gets written to COM port (and thus sent back to display pole)
def update_display_pole
begin
SerialPort.open(Rails.configuration.serial_port,
Rails.configuration.serial_port_baud_rate,
Rails.configuration.serial_port_bits,
Rails.configuration.serial_port_parity,
Rails.configuration.serial_port_flow) do |s|
s.write request.headers['X-Message']
end
head :no_content
rescue
head :internal_server_error, 'X-Reason'=> "Cannot communicate with COM port"
end
end
Now in production mode if the COM port doesn't exist, the begin/rescue block works as expected. However in development mode I don't get any errors other than "500 server error" in my logs.
Normally I use SerialPort on a server which has a virtual COM port set up to communicate over the LAN with another computer's point of sale display pole. This is set up as COM3 on the server. Everything works as expected...in production mode only. Having scoured the web for the error that was popping up, I came across a solution where I have to set config.cache_classes = true in development mode. Here's a sample of the code I'm using; keep in mind that regardless of whether or not I have a begin/rescue block, WEBrick still servers a 500 server error. I have to exit the controller method prematurely and return head :no_content before anything happens with SerialPort if I want to avoid this problem in development mode:
POST method - Ajax request from browser app has header X-Message which gets written to COM port (and thus sent back to display pole)
Now in production mode if the COM port doesn't exist, the begin/rescue block works as expected. However in development mode I don't get any errors other than "500 server error" in my logs.