DMX protocol…
# 1:break + 1:start + 512:channel
python:
import serial
class DMX512:
def __init__(self, port):
self.serial = serial.Serial(
port=port,
baudrate=250000,
bytesize=serial.EIGHTBITS,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_TWO,
timeout=0
)
self.data=[0]*513 # 513 bytes = 1:start + 512:channel
def setChannel(self, chan, intensity):
self.data[chan] = intensity
def setAll(self,col):
for i in range(1, 513):
self.data[i] = col
def update(self):
# break use or serial.send_break or serial.break_condition
self.serial.send_break(0.0001) # 100us but not precise on different OSs
# 513 bytes = 1:start + 512:channel
self.serial.write(bytes(self.data))
dmx = DMX512( 'COM3' )
dmx.setAll(255)
dmx.update()
stm8s:
====BREAK====:
UART3_Init(
(u32)45500,
UART3_WORDLENGTH_9D,
UART3_STOPBITS_1,
UART3_PARITY_NO,
UART3_MODE_TXRX_ENABLE
);
UART3_SendData9( 0x0100 | 0x00 );
====TX/RX====:
UART3_Init(
(u32)250000,
UART3_WORDLENGTH_9D,
UART3_STOPBITS_1,
UART3_PARITY_NO,
UART3_MODE_TXRX_ENABLE
);
UART3_SendData9( 0x0100 | data ); /// 513 BYTES
====rx====:
u8 dmx_buffer[513];
u16 dmx_buffer_idx;
BOOL DMX_FLAG = FALSE;
BOOL SC_FLAG = FALSE;
void UART3_RX_IRQHandler( void )
{
BOOL BREAK_FLAG = FALSE;
u8 rx = 0;
/// DMX512 = 1:break + 1:start + 512:data
if(UART3_GetITStatus(UART3_IT_RXNE )!= RESET)
{
BREAK_FLAG = UART3_ReceiveData9()>>8;
rx = UART3_ReceiveData8();
if(BREAK_FLAG == FALSE) /// 1:break
{
if(rx == 0x00)
{
SC_FLAG = TRUE;
return ;
}
}
if((BREAK_FLAG == TRUE)&&(SC_FLAG == TRUE)) /// 1:start
{
SC_FLAG = FALSE;
if(rx == 0x00)
{
DMX_FLAG = TRUE;
dmx_buffer_idx = 1; /// fill buff start from idx=1
return;
}
}
if((BREAK_FLAG == TRUE)&&(DMX_FLAG == TRUE)) /// 512:data
{
if( dmx_buffer_idx < sizeof(dmx_buffer) )
{
dmx_buffer[dmx_buffer_idx] = rx;
dmx_buffer_idx++;
}
}
}
}
訂閱:
張貼留言 (Atom)
VirtualBox 空間減肥
sdelete64 -z c: VBoxManage modifymedium disk "/Users/fellow/VirtualBox VMs/Win10/Win10.vdi" --compact *.vdi 路徑可以在 VirtualBox 儲...
-
https://github.com/ljean/modbus-tk/ install pip… sudo apt-get install python-pip install... download modbus_tk-x.x.x.tar.gz tar zxvf...
-
ARis... ARis 是日本一間公司出品的產品,應用了 ARToolKit 技術。 展示影片在這… http://www.youtube.com/watch?v=yCCx7zANsGE YouTube上可以找到更多類似的影片。 這邊是我用 FLARToolK...
-
由於ASSEMBLA即將開始收費,因此要把所有的SVN進行大搬家,連帶的一些教學文件也跟著搬家了,看來還是GOOGLE的窩最舒適(重點是免費) FPPA實驗平台教學教材-使用C語言 FPPA實驗平台簡介 實驗(一) 8位元LED輸出單元 與 模組設計總論 實驗(二) 按鍵開關輸入...
沒有留言:
張貼留言